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

Constructor & Destructor Documentation

template<class _Type>
virtual Concurrency::details::_AsyncOriginator< _Type >::~_AsyncOriginator ( )
inlinevirtual
12987  {
12988  unlink_targets();
12989 
12990  delete _M_pMessage;
12991  }
virtual void unlink_targets()
When overridden in a derived class, unlinks all target blocks from this ISource block.
Definition: agents.h:13023
message< _Type > * _M_pMessage
Definition: agents.h:13258
template<class _Type>
Concurrency::details::_AsyncOriginator< _Type >::_AsyncOriginator ( )
inlineprivate
13179  :
13180  _M_pMessage(NULL),
13181  _M_refcount(0)
13182  {
13183  }
#define NULL
Definition: crtdbg.h:30
volatile long _M_refcount
Definition: agents.h:13261
message< _Type > * _M_pMessage
Definition: agents.h:13258

Member Function Documentation

template<class _Type>
void Concurrency::details::_AsyncOriginator< _Type >::_Acquire_ref ( )
inlineprivate
13242  {
13244  }
volatile long _M_refcount
Definition: agents.h:13261
long __cdecl _InterlockedIncrement(long volatile *)
template<class _Type>
bool Concurrency::details::_AsyncOriginator< _Type >::_internal_send ( ITarget< _Type > *  _PTarget,
_Type const &  _Value 
)
inlineprivate
13187  {
13188  // Keep a refcount so that this object doesn't get deleted if
13189  // the target decides to unlink before we release our lock
13190  _Acquire_ref();
13191 
13192  message_status _Status = declined;
13193  message<_Type> * _Msg = new message<_Type>(_Value);
13194 
13195  {
13196  // Hold the lock to ensure that the target doesn't unlink while
13197  // propagation is in progress.
13198  _R_lock _Lock(_M_internalLock);
13199 
13200  // link to the target, create a message and send it
13201  link_target(_PTarget);
13202 
13204  _M_pMessage = _Msg;
13205 
13206  _Status = _PTarget->propagate(_M_pMessage, this);
13207  }
13208 
13209  // If the status is anything other than postponed, unlink away
13210  // from the target and delete the AsyncOriginator.
13211  if (_Status != postponed)
13212  {
13213  unlink_target(_PTarget);
13214  }
13215 
13216  // Release the reference acquired above
13217  _Release_ref();
13218 
13219  return (_Status == accepted);
13220  }
_CRTIMP _In_ int _Value
Definition: setjmp.h:190
#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::_Scoped_lock _R_lock
A lock holder that acquires a reentrant lock on instantiation and releases it on destruction ...
Definition: agents.h:64
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:13264
The target accepted the message.
Definition: agents.h:1745
void _Acquire_ref()
Definition: agents.h:13241
virtual void link_target(ITarget< _Type > *_PTarget)
Definition: agents.h:13223
void _Release_ref()
Definition: agents.h:13248
message< _Type > * _M_pMessage
Definition: agents.h:13258
virtual void unlink_target(ITarget< _Type > *_PTarget)
Definition: agents.h:12994
template<class _Type>
void Concurrency::details::_AsyncOriginator< _Type >::_Release_ref ( )
inlineprivate
13249  {
13252  {
13253  delete this;
13254  }
13255  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
volatile long _M_refcount
Definition: agents.h:13261
long __cdecl _InterlockedDecrement(long volatile *)
template<class _Type>
virtual message<_Type>* Concurrency::details::_AsyncOriginator< _Type >::accept ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
13059  {
13060  if (_PTarget == NULL)
13061  {
13062  return NULL;
13063  }
13064 
13065  if (!_M_connectedTargets.contains(_PTarget))
13066  {
13067  return NULL;
13068  }
13069 
13070  if (_M_pMessage == NULL || _M_pMessage->msg_id() != _MsgId)
13071  {
13072  return NULL;
13073  }
13074 
13075  //
13076  // If the IDs match, actaully transfer ownership of the message.
13077  //
13078  message<_Type> * _Result = _M_pMessage;
13079  _M_pMessage = NULL;
13080 
13081  return _Result;
13082  }
#define NULL
Definition: crtdbg.h:30
_Target_registry _M_connectedTargets
Definition: agents.h:13267
message< _Type > * _M_pMessage
Definition: agents.h:13258
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 >.

13164  {
13165  _Acquire_ref();
13166  }
void _Acquire_ref()
Definition: agents.h:13241
template<class _Type>
virtual message<_Type>* Concurrency::details::_AsyncOriginator< _Type >::consume ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
13110  {
13111  if (_PTarget == NULL)
13112  {
13113  throw std::invalid_argument("_PTarget");
13114  }
13115 
13116  if (!_M_connectedTargets.contains(_PTarget))
13117  {
13118  throw bad_target();
13119  }
13120 
13121  if (_M_pMessage == NULL || _M_pMessage->msg_id() != _MsgId)
13122  {
13123  return NULL;
13124  }
13125 
13126  // The ownership of this message has changed. Set the internal pointer to NULL
13127  // so it won't be deleted in the destructor
13128 
13129  message<_Type> * _Result = _M_pMessage;
13130  _M_pMessage = NULL;
13131 
13132  // We are done. Unlink from the target. DO NOT TOUCH "this" pointer after unlink
13133  unlink_target(_PTarget);
13134 
13135  return _Result;
13136  }
#define NULL
Definition: crtdbg.h:30
_Target_registry _M_connectedTargets
Definition: agents.h:13267
message< _Type > * _M_pMessage
Definition: agents.h:13258
virtual void unlink_target(ITarget< _Type > *_PTarget)
Definition: agents.h:12994
template<class _Type>
virtual void Concurrency::details::_AsyncOriginator< _Type >::link_target ( ITarget< _Type > *  _PTarget)
inlineprivatevirtual
13224  {
13225  if (_PTarget == NULL)
13226  {
13227  throw std::invalid_argument("_PTarget");
13228  }
13229 
13230  // Acquire a reference that will be released by unlink_target
13231  _Acquire_ref();
13232  _M_connectedTargets.add(_PTarget);
13233  _Invoke_link_source(_PTarget);
13234 
13235  // There should be no pending messages to propagate at this time.
13237 
13238  }
#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
_Target_registry _M_connectedTargets
Definition: agents.h:13267
void _Acquire_ref()
Definition: agents.h:13241
message< _Type > * _M_pMessage
Definition: agents.h:13258
template<class _Type>
virtual void Concurrency::details::_AsyncOriginator< _Type >::release ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
13142  {
13143  if (_PTarget == NULL)
13144  {
13145  throw std::invalid_argument("_PTarget");
13146  }
13147 
13148  if (!_M_connectedTargets.contains(_PTarget))
13149  {
13150  throw bad_target();
13151  }
13152 
13153  if ((_M_pMessage == NULL) || (_M_pMessage->msg_id() != _MsgId))
13154  {
13155  throw message_not_found();
13156  }
13157 
13158  // We can be connected to only 1 target. Unlink from the target.
13159  // DO NOT TOUCH "this" pointer after unlink
13160  unlink_target(_PTarget);
13161  }
#define NULL
Definition: crtdbg.h:30
_Target_registry _M_connectedTargets
Definition: agents.h:13267
message< _Type > * _M_pMessage
Definition: agents.h:13258
virtual void unlink_target(ITarget< _Type > *_PTarget)
Definition: agents.h:12994
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 >.

13169  {
13170  _Release_ref();
13171  }
void _Release_ref()
Definition: agents.h:13248
template<class _Type>
virtual bool Concurrency::details::_AsyncOriginator< _Type >::reserve ( runtime_object_identity  _MsgId,
ITarget< _Type > *  _PTarget 
)
inlinevirtual
13088  {
13089  if (_PTarget == NULL)
13090  {
13091  throw std::invalid_argument("_PTarget");
13092  }
13093 
13094  if (!_M_connectedTargets.contains(_PTarget))
13095  {
13096  return false;
13097  }
13098 
13099  if (_M_pMessage == NULL || _M_pMessage->msg_id() != _MsgId)
13100  {
13101  return false;
13102  }
13103 
13104  return true;
13105  }
#define NULL
Definition: crtdbg.h:30
_Target_registry _M_connectedTargets
Definition: agents.h:13267
message< _Type > * _M_pMessage
Definition: agents.h:13258
template<class _Type>
virtual void Concurrency::details::_AsyncOriginator< _Type >::unlink_target ( ITarget< _Type > *  _PTarget)
inlinevirtual
12995  {
12996  if (_PTarget == NULL)
12997  {
12998  throw std::invalid_argument("_PTarget");
12999  }
13000 
13001  bool _Unlinked = false;
13002  {
13003  // Hold the lock to ensure that the target doesn't unlink while
13004  // propagation is in progress.
13005  _R_lock _Lock(_M_internalLock);
13006 
13007  if (_M_connectedTargets.remove(_PTarget))
13008  {
13009  _Invoke_unlink_source(_PTarget);
13010  _Unlinked = true;
13011  }
13012  }
13013 
13014  // Release the lock before decrementing the refcount. Otherwise, the
13015  // lock release could corrupt memory.
13016  if (_Unlinked)
13017  {
13018  _Release_ref();
13019  }
13020  }
#define NULL
Definition: crtdbg.h:30
_Target_registry _M_connectedTargets
Definition: agents.h:13267
void _Invoke_unlink_source(ITarget< _Type > *_PUnlinkFrom)
Unlinks this source from a target.
Definition: agents.h:2772
::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
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:13264
void _Release_ref()
Definition: agents.h:13248
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 >.

13024  {
13025  bool _Unlinked = false;
13026  {
13027  // Hold the lock to ensure that the target doesn't unlink while
13028  // propagation is in progress.
13029  _R_lock _Lock(_M_internalLock);
13030 
13032  *_Iter != NULL;
13033  ++_Iter)
13034  {
13035  ITarget<_Type> * _PTarget = *_Iter;
13036  if (_M_connectedTargets.remove(_PTarget))
13037  {
13038  _Invoke_unlink_source(_PTarget);
13039  _Unlinked = true;
13040  }
13041 
13042  }
13043 
13044  // All targets should be unlinked
13046  }
13047 
13048  // Release the lock before decrementing the refcount. Otherwise, the
13049  // lock release could corrupt memory.
13050  if (_Unlinked)
13051  {
13052  _Release_ref();
13053  }
13054  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
#define NULL
Definition: crtdbg.h:30
_Target_registry _M_connectedTargets
Definition: agents.h:13267
void _Invoke_unlink_source(ITarget< _Type > *_PUnlinkFrom)
Unlinks this source from a target.
Definition: agents.h:2772
::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
::Concurrency::details::_ReentrantPPLLock _M_internalLock
Definition: agents.h:13264
void _Release_ref()
Definition: agents.h:13248

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: