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
12699  :
12700  _M_pMessage(NULL),
12703  {
12704  }
volatile long _M_referenceCount
Definition: agents.h:12974
The target postponed the message.
Definition: agents.h:1755
#define NULL
Definition: crtdbg.h:30
message< _Type > * _M_pMessage
Definition: agents.h:12960
volatile message_status _M_fStatus
Definition: agents.h:12966
template<class _Type>
virtual Concurrency::details::_SyncOriginator< _Type >::~_SyncOriginator ( )
inlinevirtual
12708  {
12709  unlink_targets();
12710 
12711  _Wait_on_ref();
12712 
12713  delete _M_pMessage;
12714  }
void _Wait_on_ref()
Definition: agents.h:12940
message< _Type > * _M_pMessage
Definition: agents.h:12960
virtual void unlink_targets()
When overridden in a derived class, unlinks all target blocks from this ISource block.
Definition: agents.h:12738

Member Function Documentation

template<class _Type>
void Concurrency::details::_SyncOriginator< _Type >::_Done ( message_status  _Status)
inlineprivate
12951  {
12952  // postponed is not a done state
12953  _CONCRT_ASSERT(_Status != postponed);
12954 
12955  _M_fStatus = _Status;
12956  _M_ev.set();
12957  }
event _M_ev
Definition: agents.h:12963
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
The target postponed the message.
Definition: agents.h:1755
_CRTIMP void set()
Signals the event.
volatile message_status _M_fStatus
Definition: agents.h:12966
template<class _Type>
bool Concurrency::details::_SyncOriginator< _Type >::_internal_send ( ITarget< _Type > *  _PTarget,
_Type const &  _Value 
)
inlineprivate
12874  {
12875  // _send should only be called once.
12876  if (_PTarget == NULL)
12877  {
12878  throw std::invalid_argument("_PTarget");
12879  }
12880 
12881  message_status _Status = declined;
12882  message<_Type> * _Msg = new message<_Type>(_Value);
12883 
12884  {
12885  // Hold the lock to ensure that the target doesn't unlink while
12886  // propagation is in progress.
12887  _R_lock _Lock(_M_internalLock);
12888 
12889  // link to the target, create a message and send it
12890  link_target(_PTarget);
12891 
12893  _M_pMessage = _Msg;
12894 
12895  // Send the message synchronously to the target
12896  _Status = _PTarget->send(_M_pMessage, this);
12897  }
12898 
12899  if (_Status == postponed)
12900  {
12901  // If the target postponed the message, wait for it to
12902  // be accepted/declined.
12904 
12905  // Procure the final status
12906  _Status = _M_fStatus;
12907  }
12908 
12909  // status should not be postponed.
12910  _CONCRT_ASSERT(_Status != postponed);
12911 
12912  return (_Status == accepted);
12913  }
_CRTIMP _In_ int _Value
Definition: setjmp.h:190
void _Wait_for_completion()
Definition: agents.h:12932
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
The target did not accept the message.
Definition: agents.h:1750
The target postponed the message.
Definition: agents.h:1755
#define NULL
Definition: crtdbg.h:30
message_status
The valid responses for an offer of a message object to a block.
Definition: agents.h:1739
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:12969
::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:64
The target accepted the message.
Definition: agents.h:1745
message< _Type > * _M_pMessage
Definition: agents.h:12960
virtual void link_target(ITarget< _Type > *_PTarget)
Definition: agents.h:12916
volatile message_status _M_fStatus
Definition: agents.h:12966
template<class _Type>
void Concurrency::details::_SyncOriginator< _Type >::_Wait_for_completion ( )
inlineprivate
12933  {
12934  // Wait for the event to be signalled
12937 
12938  }
_CRTIMP size_t wait(unsigned int _Timeout=COOPERATIVE_TIMEOUT_INFINITE)
Waits for the event to become signaled.
event _M_ev
Definition: agents.h:12963
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
The target postponed the message.
Definition: agents.h:1755
const unsigned int COOPERATIVE_TIMEOUT_INFINITE
Value indicating that a wait should never time out.
Definition: concrt.h:3538
volatile message_status _M_fStatus
Definition: agents.h:12966
template<class _Type>
void Concurrency::details::_SyncOriginator< _Type >::_Wait_on_ref ( )
inlineprivate
12941  {
12943  while(_M_referenceCount != 0)
12944  {
12945  spinWait._SpinOnce();
12946  }
12947  }
volatile long _M_referenceCount
Definition: agents.h:12974
Implements busy wait with no backoff
Definition: concrt.h:604
bool _SpinOnce()
Spins for one time quantum,until a maximum spin is reached.
Definition: concrt.h:652
template<class _Type>
virtual message<_Type>* Concurrency::details::_SyncOriginator< _Type >::accept ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
12763  {
12764  if (_PTarget == NULL)
12765  {
12766  return NULL;
12767  }
12768 
12769  if (!_M_connectedTargets.contains(_PTarget))
12770  {
12771  return NULL;
12772  }
12773 
12774  if (_M_pMessage == NULL || _M_pMessage->msg_id() != _MsgId)
12775  {
12776  return NULL;
12777  }
12778 
12779  // The IDs match, actaully transfer ownership of the message and
12780  // unlink away from the target
12781  message<_Type> * _Result = _M_pMessage;
12782 
12783  // The ownership of this message has changed. Set the internal pointer to NULL
12784  // so it won't be deleted in the destructor
12785  _M_pMessage = NULL;
12786 
12787  // The message has been accepted/consumed, propagate indication that it has succeeded
12788  _Done(accepted);
12789 
12790  return _Result;
12791  }
void _Done(message_status _Status)
Definition: agents.h:12950
#define NULL
Definition: crtdbg.h:30
The target accepted the message.
Definition: agents.h:1745
message< _Type > * _M_pMessage
Definition: agents.h:12960
_Target_registry _M_connectedTargets
Definition: agents.h:12972
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 >.

12859  {
12861  }
volatile long _M_referenceCount
Definition: agents.h:12974
long __cdecl _InterlockedIncrement(long volatile *)
template<class _Type>
virtual message<_Type>* Concurrency::details::_SyncOriginator< _Type >::consume ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
12819  {
12820  if (_PTarget == NULL)
12821  {
12822  throw std::invalid_argument("_PTarget");
12823  }
12824 
12825  if (!_M_connectedTargets.contains(_PTarget))
12826  {
12827  throw bad_target();
12828  }
12829 
12830  return accept(_MsgId, _PTarget);
12831  }
#define NULL
Definition: crtdbg.h:30
virtual message< _Type > * accept(runtime_object_identity _MsgId, ITarget< _Type > *_PTarget)
Definition: agents.h:12762
_Target_registry _M_connectedTargets
Definition: agents.h:12972
template<class _Type>
virtual void Concurrency::details::_SyncOriginator< _Type >::link_target ( ITarget< _Type > *  _PTarget)
inlineprivatevirtual
12917  {
12918  if (_PTarget == NULL)
12919  {
12920  throw std::invalid_argument("_PTarget");
12921  }
12922 
12923  _M_connectedTargets.add(_PTarget);
12924  _Invoke_link_source(_PTarget);
12925 
12926  // There should be no pending messages to propagate at this time.
12928  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
#define NULL
Definition: crtdbg.h:30
void _Invoke_link_source(ITarget< _Type > *_PLinkFrom)
Links this source to a target.
Definition: agents.h:2753
message< _Type > * _M_pMessage
Definition: agents.h:12960
_Target_registry _M_connectedTargets
Definition: agents.h:12972
template<class _Type>
virtual void Concurrency::details::_SyncOriginator< _Type >::release ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
12837  {
12838  if (_PTarget == NULL)
12839  {
12840  throw std::invalid_argument("_PTarget");
12841  }
12842 
12843  if (!_M_connectedTargets.contains(_PTarget))
12844  {
12845  throw bad_target();
12846  }
12847 
12848  if ((_M_pMessage == NULL) || (_M_pMessage->msg_id() != _MsgId))
12849  {
12850  throw message_not_found();
12851  }
12852 
12853  // If the previously reserved message is released, then propagate
12854  // declined to indicate that the message was not accepted.
12855  _Done(declined);
12856  }
void _Done(message_status _Status)
Definition: agents.h:12950
The target did not accept the message.
Definition: agents.h:1750
#define NULL
Definition: crtdbg.h:30
message< _Type > * _M_pMessage
Definition: agents.h:12960
_Target_registry _M_connectedTargets
Definition: agents.h:12972
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 >.

12864  {
12866  }
volatile long _M_referenceCount
Definition: agents.h:12974
long __cdecl _InterlockedDecrement(long volatile *)
template<class _Type>
virtual bool Concurrency::details::_SyncOriginator< _Type >::reserve ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
12797  {
12798  if (_PTarget == NULL)
12799  {
12800  throw std::invalid_argument("_PTarget");
12801  }
12802 
12803  if (!_M_connectedTargets.contains(_PTarget))
12804  {
12805  return false;
12806  }
12807 
12808  if (_M_pMessage->msg_id() != _MsgId)
12809  {
12810  return false;
12811  }
12812 
12813  return true;
12814  }
#define NULL
Definition: crtdbg.h:30
message< _Type > * _M_pMessage
Definition: agents.h:12960
_Target_registry _M_connectedTargets
Definition: agents.h:12972
template<class _Type>
virtual void Concurrency::details::_SyncOriginator< _Type >::unlink_target ( ITarget< _Type > *  _PTarget)
inlinevirtual
12718  {
12719  if (_PTarget == NULL)
12720  {
12721  throw std::invalid_argument("_PTarget");
12722  }
12723  {
12724  // Hold the lock to ensure that the target doesn't unlink while
12725  // propagation is in progress.
12726  _R_lock _Lock(_M_internalLock);
12727  if (_M_connectedTargets.remove(_PTarget))
12728  {
12729  _Invoke_unlink_source(_PTarget);
12730 
12731  // Indicate that the send is complete
12732  _Done(declined);
12733  }
12734  }
12735  }
void _Done(message_status _Status)
Definition: agents.h:12950
The target did not accept the message.
Definition: agents.h:1750
#define NULL
Definition: crtdbg.h:30
void _Invoke_unlink_source(ITarget< _Type > *_PUnlinkFrom)
Unlinks this source from a target.
Definition: agents.h:2772
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:12969
::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:64
_Target_registry _M_connectedTargets
Definition: agents.h:12972
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 >.

12739  {
12740  // Hold the lock to ensure that the target doesn't unlink while
12741  // propagation is in progress.
12742  _R_lock _Lock(_M_internalLock);
12743 
12744  for (_Target_registry::iterator _Iter = _M_connectedTargets.begin(); *_Iter != NULL; ++_Iter)
12745  {
12746  ITarget<_Type> * _PTarget = *_Iter;
12747  if (_M_connectedTargets.remove(_PTarget))
12748  {
12749  _Invoke_unlink_source(_PTarget);
12750  }
12751  }
12752 
12753  // All targets should be unlinked
12755 
12756  // Indicate that the send is complete
12757  _Done(declined);
12758  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
void _Done(message_status _Status)
Definition: agents.h:12950
The target did not accept the message.
Definition: agents.h:1750
#define NULL
Definition: crtdbg.h:30
void _Invoke_unlink_source(ITarget< _Type > *_PUnlinkFrom)
Unlinks this source from a target.
Definition: agents.h:2772
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:12969
::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:64
_Target_registry _M_connectedTargets
Definition: agents.h:12972

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: