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::_AsyncOriginator< _Type > Class Template Reference

#include <agents.h>

Inheritance diagram for Concurrency::details::_AsyncOriginator< _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

virtual ~_AsyncOriginator ()
 
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

 _AsyncOriginator ()
 
bool _internal_send (ITarget< _Type > *_PTarget, _Type const &_Value)
 
virtual void link_target (ITarget< _Type > *_PTarget)
 
void _Acquire_ref ()
 
void _Release_ref ()
 

Private Attributes

message< _Type > * _M_pMessage
 
volatile long _M_refcount
 
::Concurrency::details::_ReentrantPPLLock _M_internalLock
 
_Target_registry _M_connectedTargets
 

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

template<class _Type>
typedef single_link_registry<ITarget<_Type> > Concurrency::details::_AsyncOriginator< _Type >::_Target_registry

Constructor & Destructor Documentation

template<class _Type>
virtual Concurrency::details::_AsyncOriginator< _Type >::~_AsyncOriginator ( )
inlinevirtual
3982  {
3983  unlink_targets();
3984 
3985  delete _M_pMessage;
3986  }
virtual void unlink_targets()
When overridden in a derived class, unlinks all target blocks from this ISource block.
Definition: agents.h:4018
message< _Type > * _M_pMessage
Definition: agents.h:4253
template<class _Type>
Concurrency::details::_AsyncOriginator< _Type >::_AsyncOriginator ( )
inlineprivate
4174  :
4175  _M_pMessage(NULL),
4176  _M_refcount(0)
4177  {
4178  }
#define NULL
Definition: vcruntime.h:236
volatile long _M_refcount
Definition: agents.h:4256
message< _Type > * _M_pMessage
Definition: agents.h:4253

Member Function Documentation

template<class _Type>
void Concurrency::details::_AsyncOriginator< _Type >::_Acquire_ref ( )
inlineprivate
4237  {
4239  }
volatile long _M_refcount
Definition: agents.h:4256
long __cdecl _InterlockedIncrement(long volatile *)
template<class _Type>
bool Concurrency::details::_AsyncOriginator< _Type >::_internal_send ( ITarget< _Type > *  _PTarget,
_Type const &  _Value 
)
inlineprivate
4182  {
4183  // Keep a refcount so that this object doesn't get deleted if
4184  // the target decides to unlink before we release our lock
4185  _Acquire_ref();
4186 
4187  message_status _Status = declined;
4188  message<_Type> * _Msg = new message<_Type>(_Value);
4189 
4190  {
4191  // Hold the lock to ensure that the target doesn't unlink while
4192  // propagation is in progress.
4193  _R_lock _Lock(_M_internalLock);
4194 
4195  // link to the target, create a message and send it
4196  link_target(_PTarget);
4197 
4199  _M_pMessage = _Msg;
4200 
4201  _Status = _PTarget->propagate(_M_pMessage, this);
4202  }
4203 
4204  // If the status is anything other than postponed, unlink away
4205  // from the target and delete the AsyncOriginator.
4206  if (_Status != postponed)
4207  {
4208  unlink_target(_PTarget);
4209  }
4210 
4211  // Release the reference acquired above
4212  _Release_ref();
4213 
4214  return (_Status == accepted);
4215  }
#define NULL
Definition: vcruntime.h:236
#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::_Scoped_lock _R_lock
A lock holder that acquires a reentrant lock on instantiation and releases it on destruction ...
Definition: agents.h:65
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:4259
The target accepted the message.
Definition: agents.h:1746
void _Acquire_ref()
Definition: agents.h:4236
virtual void link_target(ITarget< _Type > *_PTarget)
Definition: agents.h:4218
void _Release_ref()
Definition: agents.h:4243
message< _Type > * _M_pMessage
Definition: agents.h:4253
_In_ int _Value
Definition: setjmp.h:173
virtual void unlink_target(ITarget< _Type > *_PTarget)
Definition: agents.h:3989
template<class _Type>
void Concurrency::details::_AsyncOriginator< _Type >::_Release_ref ( )
inlineprivate
4244  {
4247  {
4248  delete this;
4249  }
4250  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
volatile long _M_refcount
Definition: agents.h:4256
long __cdecl _InterlockedDecrement(long volatile *)
template<class _Type>
virtual message<_Type>* Concurrency::details::_AsyncOriginator< _Type >::accept ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
4054  {
4055  if (_PTarget == NULL)
4056  {
4057  return NULL;
4058  }
4059 
4060  if (!_M_connectedTargets.contains(_PTarget))
4061  {
4062  return NULL;
4063  }
4064 
4065  if (_M_pMessage == NULL || _M_pMessage->msg_id() != _MsgId)
4066  {
4067  return NULL;
4068  }
4069 
4070  //
4071  // If the IDs match, actually transfer ownership of the message.
4072  //
4073  message<_Type> * _Result = _M_pMessage;
4074  _M_pMessage = NULL;
4075 
4076  return _Result;
4077  }
#define NULL
Definition: vcruntime.h:236
_Target_registry _M_connectedTargets
Definition: agents.h:4262
message< _Type > * _M_pMessage
Definition: agents.h:4253
template<class _Type>
virtual void Concurrency::details::_AsyncOriginator< _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 >.

4159  {
4160  _Acquire_ref();
4161  }
void _Acquire_ref()
Definition: agents.h:4236
template<class _Type>
virtual message<_Type>* Concurrency::details::_AsyncOriginator< _Type >::consume ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
4105  {
4106  if (_PTarget == NULL)
4107  {
4108  throw std::invalid_argument("_PTarget");
4109  }
4110 
4111  if (!_M_connectedTargets.contains(_PTarget))
4112  {
4113  throw bad_target();
4114  }
4115 
4116  if (_M_pMessage == NULL || _M_pMessage->msg_id() != _MsgId)
4117  {
4118  return NULL;
4119  }
4120 
4121  // The ownership of this message has changed. Set the internal pointer to NULL
4122  // so it won't be deleted in the destructor
4123 
4124  message<_Type> * _Result = _M_pMessage;
4125  _M_pMessage = NULL;
4126 
4127  // We are done. Unlink from the target. DO NOT TOUCH "this" pointer after unlink
4128  unlink_target(_PTarget);
4129 
4130  return _Result;
4131  }
#define NULL
Definition: vcruntime.h:236
_Target_registry _M_connectedTargets
Definition: agents.h:4262
message< _Type > * _M_pMessage
Definition: agents.h:4253
virtual void unlink_target(ITarget< _Type > *_PTarget)
Definition: agents.h:3989
template<class _Type>
virtual void Concurrency::details::_AsyncOriginator< _Type >::link_target ( ITarget< _Type > *  _PTarget)
inlineprivatevirtual
4219  {
4220  if (_PTarget == NULL)
4221  {
4222  throw std::invalid_argument("_PTarget");
4223  }
4224 
4225  // Acquire a reference that will be released by unlink_target
4226  _Acquire_ref();
4227  _M_connectedTargets.add(_PTarget);
4228  _Invoke_link_source(_PTarget);
4229 
4230  // There should be no pending messages to propagate at this time.
4232 
4233  }
#define NULL
Definition: vcruntime.h:236
#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
_Target_registry _M_connectedTargets
Definition: agents.h:4262
void _Acquire_ref()
Definition: agents.h:4236
message< _Type > * _M_pMessage
Definition: agents.h:4253
template<class _Type>
virtual void Concurrency::details::_AsyncOriginator< _Type >::release ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
4137  {
4138  if (_PTarget == NULL)
4139  {
4140  throw std::invalid_argument("_PTarget");
4141  }
4142 
4143  if (!_M_connectedTargets.contains(_PTarget))
4144  {
4145  throw bad_target();
4146  }
4147 
4148  if ((_M_pMessage == NULL) || (_M_pMessage->msg_id() != _MsgId))
4149  {
4150  throw message_not_found();
4151  }
4152 
4153  // We can be connected to only 1 target. Unlink from the target.
4154  // DO NOT TOUCH "this" pointer after unlink
4155  unlink_target(_PTarget);
4156  }
#define NULL
Definition: vcruntime.h:236
_Target_registry _M_connectedTargets
Definition: agents.h:4262
message< _Type > * _M_pMessage
Definition: agents.h:4253
virtual void unlink_target(ITarget< _Type > *_PTarget)
Definition: agents.h:3989
template<class _Type>
virtual void Concurrency::details::_AsyncOriginator< _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 >.

4164  {
4165  _Release_ref();
4166  }
void _Release_ref()
Definition: agents.h:4243
template<class _Type>
virtual bool Concurrency::details::_AsyncOriginator< _Type >::reserve ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
4083  {
4084  if (_PTarget == NULL)
4085  {
4086  throw std::invalid_argument("_PTarget");
4087  }
4088 
4089  if (!_M_connectedTargets.contains(_PTarget))
4090  {
4091  return false;
4092  }
4093 
4094  if (_M_pMessage == NULL || _M_pMessage->msg_id() != _MsgId)
4095  {
4096  return false;
4097  }
4098 
4099  return true;
4100  }
#define NULL
Definition: vcruntime.h:236
_Target_registry _M_connectedTargets
Definition: agents.h:4262
message< _Type > * _M_pMessage
Definition: agents.h:4253
template<class _Type>
virtual void Concurrency::details::_AsyncOriginator< _Type >::unlink_target ( ITarget< _Type > *  _PTarget)
inlinevirtual
3990  {
3991  if (_PTarget == NULL)
3992  {
3993  throw std::invalid_argument("_PTarget");
3994  }
3995 
3996  bool _Unlinked = false;
3997  {
3998  // Hold the lock to ensure that the target doesn't unlink while
3999  // propagation is in progress.
4000  _R_lock _Lock(_M_internalLock);
4001 
4002  if (_M_connectedTargets.remove(_PTarget))
4003  {
4004  _Invoke_unlink_source(_PTarget);
4005  _Unlinked = true;
4006  }
4007  }
4008 
4009  // Release the lock before decrementing the refcount. Otherwise, the
4010  // lock release could corrupt memory.
4011  if (_Unlinked)
4012  {
4013  _Release_ref();
4014  }
4015  }
#define NULL
Definition: vcruntime.h:236
_Target_registry _M_connectedTargets
Definition: agents.h:4262
void _Invoke_unlink_source(ITarget< _Type > *_PUnlinkFrom)
Unlinks this source from a target.
Definition: agents.h:2773
::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
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:4259
void _Release_ref()
Definition: agents.h:4243
template<class _Type>
virtual void Concurrency::details::_AsyncOriginator< _Type >::unlink_targets ( )
inlinevirtual

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

Implements Concurrency::ISource< _Type >.

4019  {
4020  bool _Unlinked = false;
4021  {
4022  // Hold the lock to ensure that the target doesn't unlink while
4023  // propagation is in progress.
4024  _R_lock _Lock(_M_internalLock);
4025 
4026  for (typename _Target_registry::iterator _Iter = _M_connectedTargets.begin();
4027  *_Iter != NULL;
4028  ++_Iter)
4029  {
4030  ITarget<_Type> * _PTarget = *_Iter;
4031  if (_M_connectedTargets.remove(_PTarget))
4032  {
4033  _Invoke_unlink_source(_PTarget);
4034  _Unlinked = true;
4035  }
4036 
4037  }
4038 
4039  // All targets should be unlinked
4041  }
4042 
4043  // Release the lock before decrementing the refcount. Otherwise, the
4044  // lock release could corrupt memory.
4045  if (_Unlinked)
4046  {
4047  _Release_ref();
4048  }
4049  }
#define NULL
Definition: vcruntime.h:236
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
_Target_registry _M_connectedTargets
Definition: agents.h:4262
void _Invoke_unlink_source(ITarget< _Type > *_PUnlinkFrom)
Unlinks this source from a target.
Definition: agents.h:2773
::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
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:4259
void _Release_ref()
Definition: agents.h:4243

Friends And Related Function Documentation

template<class _Type>
friend class _Originator
friend

Member Data Documentation

template<class _Type>
_Target_registry Concurrency::details::_AsyncOriginator< _Type >::_M_connectedTargets
private
template<class _Type>
::Concurrency::details::_ReentrantPPLLock Concurrency::details::_AsyncOriginator< _Type >::_M_internalLock
private
template<class _Type>
message<_Type>* Concurrency::details::_AsyncOriginator< _Type >::_M_pMessage
private
template<class _Type>
volatile long Concurrency::details::_AsyncOriginator< _Type >::_M_refcount
private

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