STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Concurrency::details::_SyncOriginator< _Type > Class Template Reference

#include <agents.h>

Inheritance diagram for Concurrency::details::_SyncOriginator< _Type >:
Concurrency::ISource< _Type >

Public Types

typedef single_link_registry< ITarget< _Type > > _Target_registry
 
- Public Types inherited from Concurrency::ISource< _Type >
typedef _Type source_type
 A type alias for _Type . More...
 

Public Member Functions

 _SyncOriginator ()
 
virtual ~_SyncOriginator ()
 
virtual void unlink_target (ITarget< _Type > *_PTarget)
 
virtual void unlink_targets ()
 When overridden in a derived class, unlinks all target blocks from this ISource block. More...
 
virtual message< _Type > * accept (runtime_object_identity _MsgId, ITarget< _Type > *_PTarget)
 
virtual bool reserve (runtime_object_identity _MsgId, ITarget< _Type > *_PTarget)
 
virtual message< _Type > * consume (runtime_object_identity _MsgId, ITarget< _Type > *_PTarget)
 
virtual void release (runtime_object_identity _MsgId, ITarget< _Type > *_PTarget)
 
virtual void acquire_ref (_Inout_ ITarget< _Type > *)
 When overridden in a derived class, acquires a reference count on this ISource block, to prevent deletion. More...
 
virtual void release_ref (_Inout_ ITarget< _Type > *)
 When overridden in a derived class, releases a reference count on this ISource block. More...
 
- Public Member Functions inherited from Concurrency::ISource< _Type >
virtual ~ISource ()
 Destroys the ISource object. More...
 
virtual void link_target (_Inout_ ITarget< _Type > *_PTarget)=0
 When overridden in a derived class, links a target block to this ISource block. More...
 
virtual void unlink_target (_Inout_ ITarget< _Type > *_PTarget)=0
 When overridden in a derived class, unlinks a target block from this ISource block, if found to be previously linked. More...
 
virtual message< _Type > * accept (runtime_object_identity _MsgId, _Inout_ ITarget< _Type > *_PTarget)=0
 When overridden in a derived class, accepts a message that was offered by this ISource block, transferring ownership to the caller. More...
 
virtual bool reserve (runtime_object_identity _MsgId, _Inout_ ITarget< _Type > *_PTarget)=0
 When overridden in a derived class, reserves a message previously offered by this ISource block. More...
 
virtual message< _Type > * consume (runtime_object_identity _MsgId, _Inout_ ITarget< _Type > *_PTarget)=0
 When overridden in a derived class, consumes a message previously offered by this ISource block and successfully reserved by the target, transferring ownership to the caller. More...
 
virtual void release (runtime_object_identity _MsgId, _Inout_ ITarget< _Type > *_PTarget)=0
 When overridden in a derived class, releases a previous successful message reservation. More...
 

Private Member Functions

bool _internal_send (ITarget< _Type > *_PTarget, _Type const &_Value)
 
virtual void link_target (ITarget< _Type > *_PTarget)
 
void _Wait_for_completion ()
 
void _Wait_on_ref ()
 
void _Done (message_status _Status)
 

Private Attributes

message< _Type > * _M_pMessage
 
event _M_ev
 
volatile message_status _M_fStatus
 
::Concurrency::details::_ReentrantPPLLock _M_internalLock
 
_Target_registry _M_connectedTargets
 
volatile long _M_referenceCount
 

Friends

class _Originator
 

Additional Inherited Members

- Protected Member Functions inherited from Concurrency::ISource< _Type >
void _Invoke_link_source (ITarget< _Type > *_PLinkFrom)
 Links this source to a target. More...
 
void _Invoke_unlink_source (ITarget< _Type > *_PUnlinkFrom)
 Unlinks this source from a target. More...
 

Member Typedef Documentation

Constructor & Destructor Documentation

template<class _Type>
Concurrency::details::_SyncOriginator< _Type >::_SyncOriginator ( )
inline
3694  :
3695  _M_pMessage(NULL),
3698  {
3699  }
volatile long _M_referenceCount
Definition: agents.h:3969
The target postponed the message.
Definition: agents.h:1756
message< _Type > * _M_pMessage
Definition: agents.h:3955
volatile message_status _M_fStatus
Definition: agents.h:3961
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual Concurrency::details::_SyncOriginator< _Type >::~_SyncOriginator ( )
inlinevirtual
3703  {
3704  unlink_targets();
3705 
3706  _Wait_on_ref();
3707 
3708  delete _M_pMessage;
3709  }
void _Wait_on_ref()
Definition: agents.h:3935
message< _Type > * _M_pMessage
Definition: agents.h:3955
virtual void unlink_targets()
When overridden in a derived class, unlinks all target blocks from this ISource block.
Definition: agents.h:3733

Member Function Documentation

template<class _Type>
void Concurrency::details::_SyncOriginator< _Type >::_Done ( message_status  _Status)
inlineprivate
3946  {
3947  // postponed is not a done state
3948  _CONCRT_ASSERT(_Status != postponed);
3949 
3950  _M_fStatus = _Status;
3951  _M_ev.set();
3952  }
event _M_ev
Definition: agents.h:3958
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
The target postponed the message.
Definition: agents.h:1756
_CONCRTIMP void set()
Signals the event.
volatile message_status _M_fStatus
Definition: agents.h:3961
template<class _Type>
bool Concurrency::details::_SyncOriginator< _Type >::_internal_send ( ITarget< _Type > *  _PTarget,
_Type const &  _Value 
)
inlineprivate
3869  {
3870  // _send should only be called once.
3871  if (_PTarget == NULL)
3872  {
3873  throw std::invalid_argument("_PTarget");
3874  }
3875 
3876  message_status _Status = declined;
3877  message<_Type> * _Msg = new message<_Type>(_Value);
3878 
3879  {
3880  // Hold the lock to ensure that the target doesn't unlink while
3881  // propagation is in progress.
3882  _R_lock _Lock(_M_internalLock);
3883 
3884  // link to the target, create a message and send it
3885  link_target(_PTarget);
3886 
3888  _M_pMessage = _Msg;
3889 
3890  // Send the message synchronously to the target
3891  _Status = _PTarget->send(_M_pMessage, this);
3892  }
3893 
3894  if (_Status == postponed)
3895  {
3896  // If the target postponed the message, wait for it to
3897  // be accepted/declined.
3899 
3900  // Procure the final status
3901  _Status = _M_fStatus;
3902  }
3903 
3904  // status should not be postponed.
3905  _CONCRT_ASSERT(_Status != postponed);
3906 
3907  return (_Status == accepted);
3908  }
void _Wait_for_completion()
Definition: agents.h:3927
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
The target did not accept the message.
Definition: agents.h:1751
The target postponed the message.
Definition: agents.h:1756
message_status
The valid responses for an offer of a message object to a block.
Definition: agents.h:1740
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:3964
::Concurrency::details::_ReentrantPPLLock::_Scoped_lock _R_lock
A lock holder that acquires a reentrant lock on instantiation and releases it on destruction ...
Definition: agents.h:65
The target accepted the message.
Definition: agents.h:1746
message< _Type > * _M_pMessage
Definition: agents.h:3955
virtual void link_target(ITarget< _Type > *_PTarget)
Definition: agents.h:3911
_In_ _Value
Definition: corecrt_wstdlib.h:65
volatile message_status _M_fStatus
Definition: agents.h:3961
#define NULL
Definition: corecrt.h:158
template<class _Type>
void Concurrency::details::_SyncOriginator< _Type >::_Wait_for_completion ( )
inlineprivate
3928  {
3929  // Wait for the event to be signalled
3932 
3933  }
event _M_ev
Definition: agents.h:3958
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
The target postponed the message.
Definition: agents.h:1756
const unsigned int COOPERATIVE_TIMEOUT_INFINITE
Value indicating that a wait should never time out.
Definition: concrt.h:3478
_CONCRTIMP size_t wait(unsigned int _Timeout=COOPERATIVE_TIMEOUT_INFINITE)
Waits for the event to become signaled.
volatile message_status _M_fStatus
Definition: agents.h:3961
template<class _Type>
void Concurrency::details::_SyncOriginator< _Type >::_Wait_on_ref ( )
inlineprivate
3936  {
3938  while(_M_referenceCount != 0)
3939  {
3940  spinWait._SpinOnce();
3941  }
3942  }
volatile long _M_referenceCount
Definition: agents.h:3969
Implements busy wait with no backoff
Definition: concrt.h:578
bool _SpinOnce()
Spins for one time quantum,until a maximum spin is reached.
Definition: concrt.h:626
template<class _Type>
virtual message<_Type>* Concurrency::details::_SyncOriginator< _Type >::accept ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
3758  {
3759  if (_PTarget == NULL)
3760  {
3761  return NULL;
3762  }
3763 
3764  if (!_M_connectedTargets.contains(_PTarget))
3765  {
3766  return NULL;
3767  }
3768 
3769  if (_M_pMessage == NULL || _M_pMessage->msg_id() != _MsgId)
3770  {
3771  return NULL;
3772  }
3773 
3774  // The IDs match. Actually transfer ownership of the message and
3775  // unlink away from the target
3776  message<_Type> * _Result = _M_pMessage;
3777 
3778  // The ownership of this message has changed. Set the internal pointer to NULL
3779  // so it won't be deleted in the destructor
3780  _M_pMessage = NULL;
3781 
3782  // The message has been accepted/consumed, propagate indication that it has succeeded
3783  _Done(accepted);
3784 
3785  return _Result;
3786  }
void _Done(message_status _Status)
Definition: agents.h:3945
The target accepted the message.
Definition: agents.h:1746
message< _Type > * _M_pMessage
Definition: agents.h:3955
_Target_registry _M_connectedTargets
Definition: agents.h:3967
_Result
Definition: corecrt_wconio.h:362
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual void Concurrency::details::_SyncOriginator< _Type >::acquire_ref ( _Inout_ ITarget< _Type > *  _PTarget)
inlinevirtual

When overridden in a derived class, acquires a reference count on this ISource block, to prevent deletion.

Parameters
_PTargetA pointer to the target block that is calling this method.

This method is called by an ITarget object that is being linked to this source during the link_target method.

Implements Concurrency::ISource< _Type >.

3854  {
3856  }
volatile long _M_referenceCount
Definition: agents.h:3969
long __cdecl _InterlockedIncrement(long volatile *)
template<class _Type>
virtual message<_Type>* Concurrency::details::_SyncOriginator< _Type >::consume ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
3814  {
3815  if (_PTarget == NULL)
3816  {
3817  throw std::invalid_argument("_PTarget");
3818  }
3819 
3820  if (!_M_connectedTargets.contains(_PTarget))
3821  {
3822  throw bad_target();
3823  }
3824 
3825  return accept(_MsgId, _PTarget);
3826  }
virtual message< _Type > * accept(runtime_object_identity _MsgId, ITarget< _Type > *_PTarget)
Definition: agents.h:3757
_Target_registry _M_connectedTargets
Definition: agents.h:3967
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual void Concurrency::details::_SyncOriginator< _Type >::link_target ( ITarget< _Type > *  _PTarget)
inlineprivatevirtual
3912  {
3913  if (_PTarget == NULL)
3914  {
3915  throw std::invalid_argument("_PTarget");
3916  }
3917 
3918  _M_connectedTargets.add(_PTarget);
3919  this->_Invoke_link_source(_PTarget);
3920 
3921  // There should be no pending messages to propagate at this time.
3923  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
void _Invoke_link_source(ITarget< _Type > *_PLinkFrom)
Links this source to a target.
Definition: agents.h:2754
message< _Type > * _M_pMessage
Definition: agents.h:3955
_Target_registry _M_connectedTargets
Definition: agents.h:3967
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual void Concurrency::details::_SyncOriginator< _Type >::release ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
3832  {
3833  if (_PTarget == NULL)
3834  {
3835  throw std::invalid_argument("_PTarget");
3836  }
3837 
3838  if (!_M_connectedTargets.contains(_PTarget))
3839  {
3840  throw bad_target();
3841  }
3842 
3843  if ((_M_pMessage == NULL) || (_M_pMessage->msg_id() != _MsgId))
3844  {
3845  throw message_not_found();
3846  }
3847 
3848  // If the previously reserved message is released, then propagate
3849  // declined to indicate that the message was not accepted.
3850  _Done(declined);
3851  }
void _Done(message_status _Status)
Definition: agents.h:3945
The target did not accept the message.
Definition: agents.h:1751
message< _Type > * _M_pMessage
Definition: agents.h:3955
_Target_registry _M_connectedTargets
Definition: agents.h:3967
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual void Concurrency::details::_SyncOriginator< _Type >::release_ref ( _Inout_ ITarget< _Type > *  _PTarget)
inlinevirtual

When overridden in a derived class, releases a reference count on this ISource block.

Parameters
_PTargetA pointer to the target block that is calling this method.

This method is called by an ITarget object that is being unlinked from this source. The source block is allowed to release any resources reserved for the target block.

Implements Concurrency::ISource< _Type >.

3859  {
3861  }
volatile long _M_referenceCount
Definition: agents.h:3969
long __cdecl _InterlockedDecrement(long volatile *)
template<class _Type>
virtual bool Concurrency::details::_SyncOriginator< _Type >::reserve ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
3792  {
3793  if (_PTarget == NULL)
3794  {
3795  throw std::invalid_argument("_PTarget");
3796  }
3797 
3798  if (!_M_connectedTargets.contains(_PTarget))
3799  {
3800  return false;
3801  }
3802 
3803  if (_M_pMessage->msg_id() != _MsgId)
3804  {
3805  return false;
3806  }
3807 
3808  return true;
3809  }
message< _Type > * _M_pMessage
Definition: agents.h:3955
_Target_registry _M_connectedTargets
Definition: agents.h:3967
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual void Concurrency::details::_SyncOriginator< _Type >::unlink_target ( ITarget< _Type > *  _PTarget)
inlinevirtual
3713  {
3714  if (_PTarget == NULL)
3715  {
3716  throw std::invalid_argument("_PTarget");
3717  }
3718  {
3719  // Hold the lock to ensure that the target doesn't unlink while
3720  // propagation is in progress.
3721  _R_lock _Lock(_M_internalLock);
3722  if (_M_connectedTargets.remove(_PTarget))
3723  {
3724  this->_Invoke_unlink_source(_PTarget);
3725 
3726  // Indicate that the send is complete
3727  _Done(declined);
3728  }
3729  }
3730  }
void _Done(message_status _Status)
Definition: agents.h:3945
The target did not accept the message.
Definition: agents.h:1751
void _Invoke_unlink_source(ITarget< _Type > *_PUnlinkFrom)
Unlinks this source from a target.
Definition: agents.h:2773
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:3964
::Concurrency::details::_ReentrantPPLLock::_Scoped_lock _R_lock
A lock holder that acquires a reentrant lock on instantiation and releases it on destruction ...
Definition: agents.h:65
_Target_registry _M_connectedTargets
Definition: agents.h:3967
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual void Concurrency::details::_SyncOriginator< _Type >::unlink_targets ( )
inlinevirtual

When overridden in a derived class, unlinks all target blocks from this ISource block.

Implements Concurrency::ISource< _Type >.

3734  {
3735  // Hold the lock to ensure that the target doesn't unlink while
3736  // propagation is in progress.
3737  _R_lock _Lock(_M_internalLock);
3738 
3739  for (typename _Target_registry::iterator _Iter = _M_connectedTargets.begin(); *_Iter != NULL; ++_Iter)
3740  {
3741  ITarget<_Type> * _PTarget = *_Iter;
3742  if (_M_connectedTargets.remove(_PTarget))
3743  {
3744  this->_Invoke_unlink_source(_PTarget);
3745  }
3746  }
3747 
3748  // All targets should be unlinked
3750 
3751  // Indicate that the send is complete
3752  _Done(declined);
3753  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
void _Done(message_status _Status)
Definition: agents.h:3945
The target did not accept the message.
Definition: agents.h:1751
void _Invoke_unlink_source(ITarget< _Type > *_PUnlinkFrom)
Unlinks this source from a target.
Definition: agents.h:2773
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:3964
::Concurrency::details::_ReentrantPPLLock::_Scoped_lock _R_lock
A lock holder that acquires a reentrant lock on instantiation and releases it on destruction ...
Definition: agents.h:65
_Target_registry _M_connectedTargets
Definition: agents.h:3967
#define NULL
Definition: corecrt.h:158

Friends And Related Function Documentation

template<class _Type>
friend class _Originator
friend

Member Data Documentation

template<class _Type>
_Target_registry Concurrency::details::_SyncOriginator< _Type >::_M_connectedTargets
private
template<class _Type>
event Concurrency::details::_SyncOriginator< _Type >::_M_ev
private
template<class _Type>
volatile message_status Concurrency::details::_SyncOriginator< _Type >::_M_fStatus
private
template<class _Type>
::Concurrency::details::_ReentrantPPLLock Concurrency::details::_SyncOriginator< _Type >::_M_internalLock
private
template<class _Type>
message<_Type>* Concurrency::details::_SyncOriginator< _Type >::_M_pMessage
private
template<class _Type>
volatile long Concurrency::details::_SyncOriginator< _Type >::_M_referenceCount
private

The documentation for this class was generated from the following file: