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

A join messaging block is a single-target, multi-source, ordered propagator_block which combines together messages of type _Type from each of its sources. More...

#include <agents.h>

Inheritance diagram for Concurrency::join< _Type, _Jtype >:
Concurrency::propagator_block< single_link_registry< ITarget< std::vector< _Type > > >, multi_link_registry< ISource< _Type > > > Concurrency::source_block< single_link_registry< ITarget< std::vector< _Type > > >, _MessageProcessorType > Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type > Concurrency::ISource< single_link_registry< ITarget< std::vector< _Type > > >::type::type >

Classes

struct  _MessageArray
 
struct  _SavedMessageIdArray
 

Public Types

typedef std::vector< _Type > _OutputType
 
- Public Types inherited from Concurrency::propagator_block< single_link_registry< ITarget< std::vector< _Type > > >, multi_link_registry< ISource< _Type > > >
typedef multi_link_registry< ISource< _Type > >::type::source_type _Source_type
 The type of the payload for the incoming message to this propagator_block. More...
 
typedef source_link_manager< multi_link_registry< ISource< _Type > > > _SourceLinkManager
 The type of the source_link_manager this propagator_block. More...
 
typedef _SourceLinkManager::iterator source_iterator
 The type of the iterator for the source_link_manager for this propagator_block. More...
 
- Public Types inherited from Concurrency::source_block< single_link_registry< ITarget< std::vector< _Type > > >, _MessageProcessorType >
typedef single_link_registry< ITarget< std::vector< _Type > > >::type::type _Target_type
 The payload type of messages handled by this source_block. More...
 
typedef single_link_registry< ITarget< std::vector< _Type > > >::iterator target_iterator
 The iterator to walk the connected targets. More...
 
- Public Types inherited from Concurrency::ISource< single_link_registry< ITarget< std::vector< _Type > > >::type::type >
typedef single_link_registry< ITarget< std::vector< _Type > > >::type::type source_type
 A type alias for _Type . More...
 
- Public Types inherited from Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type >
typedef multi_link_registry< ISource< _Type > >::type::source_type type
 A type alias for _Type . More...
 
typedef std::function< bool(multi_link_registry< ISource< _Type > >::type::source_typeconst &)> filter_method
 The signature of any method used by the block that returns a bool value to determine whether an offered message should be accepted. More...
 

Public Member Functions

 join (size_t _NumInputs)
 Constructs a join messaging block. More...
 
 join (size_t _NumInputs, filter_method const &_Filter)
 Constructs a join messaging block. More...
 
 ~join ()
 Destroys the join block. More...
 
- Public Member Functions inherited from Concurrency::propagator_block< single_link_registry< ITarget< std::vector< _Type > > >, multi_link_registry< ISource< _Type > > >
 propagator_block ()
 Constructs a propagator_block object. More...
 
virtual ~propagator_block ()
 Destroys a propagator_block object. More...
 
virtual message_status propagate (_Inout_opt_ message< _Source_type > *_PMessage, _Inout_opt_ ISource< _Source_type > *_PSource)
 Asynchronously passes a message from a source block to this target block. More...
 
virtual message_status send (_Inout_ message< _Source_type > *_PMessage, _Inout_ ISource< _Source_type > *_PSource)
 Synchronously initiates a message to this block. Called by an ISource block. When this function completes, the message will already have propagated into the block. More...
 
- Public Member Functions inherited from Concurrency::source_block< single_link_registry< ITarget< std::vector< _Type > > >, _MessageProcessorType >
 source_block ()
 Constructs a source_block object. More...
 
virtual ~source_block ()
 Destroys the source_block object. More...
 
virtual void link_target (_Inout_ ITarget< _Target_type > *_PTarget)
 Links a target block to this source_block object. More...
 
virtual void unlink_target (_Inout_ ITarget< _Target_type > *_PTarget)
 Unlinks a target block from this source_block object. More...
 
virtual void unlink_targets ()
 Unlinks all target blocks from this source_block object. More...
 
virtual message< _Target_type > * accept (runtime_object_identity _MsgId, _Inout_ ITarget< _Target_type > *_PTarget)
 Accepts a message that was offered by this source_block object, transferring ownership to the caller. More...
 
virtual bool reserve (runtime_object_identity _MsgId, _Inout_ ITarget< _Target_type > *_PTarget)
 Reserves a message previously offered by this source_block object. More...
 
virtual message< _Target_type > * consume (runtime_object_identity _MsgId, _Inout_ ITarget< _Target_type > *_PTarget)
 Consumes a message previously offered by this source_block object and successfully reserved by the target, transferring ownership to the caller. More...
 
virtual void release (runtime_object_identity _MsgId, _Inout_ ITarget< _Target_type > *_PTarget)
 Releases a previous successful message reservation. More...
 
virtual void acquire_ref (_Inout_ ITarget< _Target_type > *)
 Acquires a reference count on this source_block object, to prevent deletion. More...
 
virtual void release_ref (_Inout_ ITarget< _Target_type > *_PTarget)
 Releases a reference count on this source_block object. More...
 
- Public Member Functions inherited from Concurrency::ISource< single_link_registry< ITarget< std::vector< _Type > > >::type::type >
virtual ~ISource ()
 Destroys the ISource object. More...
 
virtual void link_target (_Inout_ ITarget< single_link_registry< ITarget< std::vector< _Type > > >::type::type > *_PTarget)=0
 When overridden in a derived class, links a target block to this ISource block. More...
 
virtual void unlink_target (_Inout_ ITarget< single_link_registry< ITarget< std::vector< _Type > > >::type::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< single_link_registry< ITarget< std::vector< _Type > > >::type::type > * accept (runtime_object_identity _MsgId, _Inout_ ITarget< single_link_registry< ITarget< std::vector< _Type > > >::type::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< single_link_registry< ITarget< std::vector< _Type > > >::type::type > *_PTarget)=0
 When overridden in a derived class, reserves a message previously offered by this ISource block. More...
 
virtual message< single_link_registry< ITarget< std::vector< _Type > > >::type::type > * consume (runtime_object_identity _MsgId, _Inout_ ITarget< single_link_registry< ITarget< std::vector< _Type > > >::type::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< single_link_registry< ITarget< std::vector< _Type > > >::type::type > *_PTarget)=0
 When overridden in a derived class, releases a previous successful message reservation. More...
 
virtual void acquire_ref (_Inout_ ITarget< single_link_registry< ITarget< std::vector< _Type > > >::type::type > *_PTarget)=0
 When overridden in a derived class, acquires a reference count on this ISource block, to prevent deletion. More...
 
virtual void release_ref (_Inout_ ITarget< single_link_registry< ITarget< std::vector< _Type > > >::type::type > *_PTarget)=0
 When overridden in a derived class, releases a reference count on this ISource block. More...
 
- Public Member Functions inherited from Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type >
virtual ~ITarget ()
 Destroys the ITarget object. More...
 
virtual message_status propagate (_Inout_opt_ message< multi_link_registry< ISource< _Type > >::type::source_type > *_PMessage, _Inout_opt_ ISource< multi_link_registry< ISource< _Type > >::type::source_type > *_PSource)=0
 When overridden in a derived class, asynchronously passes a message from a source block to this target block. More...
 
virtual message_status send (_Inout_ message< multi_link_registry< ISource< _Type > >::type::source_type > *_PMessage, _Inout_ ISource< multi_link_registry< ISource< _Type > >::type::source_type > *_PSource)=0
 When overridden in a derived class, synchronously passes a message to the target block. More...
 
virtual bool supports_anonymous_source ()
 When overridden in a derived class, returns true or false depending on whether the message block accepts messages offered by a source that is not linked to it. If the overridden method returns true, the target cannot postpone an offered message, as consumption of a postponed message at a later time requires the source to be identified in its source link registry. More...
 

Protected Member Functions

message_status propagate_message (_Inout_ message< _Type > *_PMessage, _Inout_ ISource< _Type > *_PSource)
 Asynchronously passes a message from an ISource block to this join messaging block. It is invoked by the propagate method, when called by a source block. More...
 
virtual message< _OutputType > * accept_message (runtime_object_identity _MsgId)
 Accepts a message that was offered by this join messaging block, transferring ownership to the caller. More...
 
virtual bool reserve_message (runtime_object_identity _MsgId)
 Reserves a message previously offered by this join messaging block. More...
 
virtual message< _OutputType > * consume_message (runtime_object_identity _MsgId)
 Consumes a message previously offered by the join messaging block and reserved by the target, transferring ownership to the caller. More...
 
virtual void release_message (runtime_object_identity _MsgId)
 Releases a previous message reservation. More...
 
virtual void resume_propagation ()
 Resumes propagation after a reservation has been released. More...
 
virtual void link_target_notification (_Inout_ ITarget< std::vector< _Type >> *)
 A callback that notifies that a new target has been linked to this join messaging block. More...
 
void propagate_to_any_targets (_Inout_opt_ message< _OutputType > *)
 Constructs an output message containing an input message from each source when they have all propagated a message. Sends this output message out to each of its targets. More...
 
- Protected Member Functions inherited from Concurrency::propagator_block< single_link_registry< ITarget< std::vector< _Type > > >, multi_link_registry< ISource< _Type > > >
virtual message_status propagate_message (_Inout_ message< _Source_type > *_PMessage, _Inout_ ISource< _Source_type > *_PSource)=0
 When overridden in a derived class, this method asynchronously passes a message from an ISource block to this propagator_block object. It is invoked by the propagate method, when called by a source block. More...
 
virtual message_status send_message (_Inout_ message< _Source_type > *, _Inout_ ISource< _Source_type > *)
 When overridden in a derived class, this method synchronously passes a message from an ISource block to this propagator_block object. It is invoked by the send method, when called by a source block. More...
 
virtual void link_source (_Inout_ ISource< _Source_type > *_PSource)
 Links a specified source block to this propagator_block object. More...
 
virtual void unlink_source (_Inout_ ISource< _Source_type > *_PSource)
 Unlinks a specified source block from this propagator_block object. More...
 
virtual void unlink_sources ()
 Unlinks all source blocks from this propagator_block object. More...
 
virtual void process_input_messages (_Inout_ message< _Target_type > *_PMessage)
 Process input messages. This is only useful for propagator blocks, which derive from source_block More...
 
void initialize_source_and_target (_Inout_opt_ Scheduler *_PScheduler=NULL, _Inout_opt_ ScheduleGroup *_PScheduleGroup=NULL)
 Initializes the base object. Specifically, the message_processor object needs to be initialized. More...
 
void register_filter (filter_method const &_Filter)
 Registers a filter method that will be invoked on every received message. More...
 
void decline_incoming_messages ()
 Indicates to the block that new messages should be declined. More...
 
void remove_network_links ()
 Removes all the source and target network links from this propagator_block object. More...
 
- Protected Member Functions inherited from Concurrency::source_block< single_link_registry< ITarget< std::vector< _Type > > >, _MessageProcessorType >
virtual void link_target_notification (_Inout_ ITarget< _Target_type > *)
 A callback that notifies that a new target has been linked to this source_block object. More...
 
virtual void unlink_target_notification (_Inout_ ITarget< _Target_type > *_PTarget)
 A callback that notifies that a target has been unlinked from this source_block object. More...
 
virtual void propagate_output_messages ()
 Propagate messages to targets. More...
 
virtual void propagate_to_any_targets (_Inout_opt_ message< _Target_type > *_PMessage)
 When overridden in a derived class, propagates the given message to any or all of the linked targets. This is the main propagation routine for message blocks. More...
 
void initialize_source (_Inout_opt_ Scheduler *_PScheduler=NULL, _Inout_opt_ ScheduleGroup *_PScheduleGroup=NULL)
 Initializes the message_propagator within this source_block. More...
 
void enable_batched_processing ()
 Enables batched processing for this block. More...
 
virtual void sync_send (_Inout_opt_ message< _Target_type > *_Msg)
 Synchronously queues up messages and starts a propagation task, if this has not been done already. More...
 
virtual void async_send (_Inout_opt_ message< _Target_type > *_Msg)
 Asynchronously queues up messages and starts a propagation task, if this has not been done already More...
 
void wait_for_outstanding_async_sends ()
 Waits for all asynchronous propagations to complete. This propagator-specific spin wait is used in destructors of message blocks to make sure that all asynchronous propagations have time to finish before destroying the block. More...
 
void remove_targets ()
 Removes all target links for this source block. This should be called from the destructor. More...
 
- Protected Member Functions inherited from Concurrency::ISource< single_link_registry< ITarget< std::vector< _Type > > >::type::type >
void _Invoke_link_source (ITarget< single_link_registry< ITarget< std::vector< _Type > > >::type::type > *_PLinkFrom)
 Links this source to a target. More...
 
void _Invoke_unlink_source (ITarget< single_link_registry< ITarget< std::vector< _Type > > >::type::type > *_PUnlinkFrom)
 Unlinks this source from a target. More...
 
- Protected Member Functions inherited from Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type >
virtual void link_source (_Inout_ ISource< multi_link_registry< ISource< _Type > >::type::source_type > *_PSource)=0
 When overridden in a derived class, links a specified source block to this ITarget block. More...
 
virtual void unlink_source (_Inout_ ISource< multi_link_registry< ISource< _Type > >::type::source_type > *_PSource)=0
 When overridden in a derived class, unlinks a specified source block from this ITarget block. More...
 

Private Types

typedef single_link_registry< ITarget< std::vector< _Type > > > _TargetLinkRegistry
 
typedef multi_link_registry< ISource< _Type > > _SourceLinkRegistry
 

Private Member Functions

void _Propagate_priority_order (::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
 Propagate messages in priority order. More...
 
message< std::vector< _Type > > *__cdecl _Create_new_message ()
 Constructs a new message from the data output. More...
 
void _Initialize (size_t _NumInputs, Scheduler *_PScheduler=NULL, ScheduleGroup *_PScheduleGroup=NULL)
 Initializes the join messaging block. More...
 
void _Delete_stored_messages ()
 Deletes all messages currently stored in this message block. Should be called by the destructor to ensure any messages propagated in are cleaned up. More...
 

Private Attributes

volatile size_t _M_messagesRemaining
 
_MessageArray _M_messageArray
 
_SavedMessageIdArray _M_savedMessageIdArray
 
runtime_object_identity_M_savedIdBuffer
 
::Concurrency::details::_NonReentrantPPLLock _M_propagationLock
 
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
 

Additional Inherited Members

- Protected Attributes inherited from Concurrency::propagator_block< single_link_registry< ITarget< std::vector< _Type > > >, multi_link_registry< ISource< _Type > > >
_SourceLinkManager _M_connectedSources
 The container for all the sources connected to this block. More...
 
filter_method_M_pFilter
 The filter function which determines whether offered messages should be accepted. More...
 
volatile bool _M_fDeclineMessages
 A bool that is set to indicate that all messages should be declined in preparation for deleting the block More...
 
- Protected Attributes inherited from Concurrency::source_block< single_link_registry< ITarget< std::vector< _Type > > >, _MessageProcessorType >
ITarget< _Target_type > * _M_pReservedFor
 Connected target that is holding a reservation More...
 
runtime_object_identity _M_reservedId
 Reserved message ID More...
 
single_link_registry< ITarget< std::vector< _Type > > > _M_connectedTargets
 Connected targets More...
 
_MessageProcessorType _M_messageProcessor
 Processor used for asynchronous message handling More...
 

Detailed Description

template<class _Type, join_type _Jtype = non_greedy>
class Concurrency::join< _Type, _Jtype >

A join messaging block is a single-target, multi-source, ordered propagator_block which combines together messages of type _Type from each of its sources.

Template Parameters
_TypeThe payload type of the messages joined and propagated by the block.
_JtypeThe kind of join block this is, either greedy or non_greedy

For more information, see Asynchronous Message Blocks.

See also
choice Class, multitype_join Class, join_type Enumeration

Member Typedef Documentation

template<class _Type , join_type _Jtype = non_greedy>
typedef std::vector<_Type> Concurrency::join< _Type, _Jtype >::_OutputType
template<class _Type , join_type _Jtype = non_greedy>
typedef multi_link_registry<ISource<_Type> > Concurrency::join< _Type, _Jtype >::_SourceLinkRegistry
private
template<class _Type , join_type _Jtype = non_greedy>
typedef single_link_registry<ITarget<std::vector<_Type> > > Concurrency::join< _Type, _Jtype >::_TargetLinkRegistry
private

Constructor & Destructor Documentation

template<class _Type , join_type _Jtype = non_greedy>
Concurrency::join< _Type, _Jtype >::join ( size_t  _NumInputs)
inline

Constructs a join messaging block.

Parameters
_NumInputsThe number of inputs this join block will be allowed.

The runtime uses the default scheduler if you do not specify the _PScheduler or _PScheduleGroup parameters.

The type filter_method is a functor with signature bool (_Type const &) which is invoked by this join messaging block to determine whether or not it should accept an offered message.

See also
Scheduler Class, ScheduleGroup Class
9183  : _M_messageArray(_NumInputs),
9184  _M_savedMessageIdArray(_NumInputs)
9185  {
9186  _Initialize(_NumInputs);
9187  }
_MessageArray _M_messageArray
Definition: agents.h:9925
void _Initialize(size_t _NumInputs, Scheduler *_PScheduler=NULL, ScheduleGroup *_PScheduleGroup=NULL)
Initializes the join messaging block.
Definition: agents.h:9856
_SavedMessageIdArray _M_savedMessageIdArray
Definition: agents.h:9950
template<class _Type , join_type _Jtype = non_greedy>
Concurrency::join< _Type, _Jtype >::join ( size_t  _NumInputs,
filter_method const &  _Filter 
)
inline

Constructs a join messaging block.

Parameters
_NumInputsThe number of inputs this join block will be allowed.
_FilterA filter function which determines whether offered messages should be accepted.

The runtime uses the default scheduler if you do not specify the _PScheduler or _PScheduleGroup parameters.

The type filter_method is a functor with signature bool (_Type const &) which is invoked by this join messaging block to determine whether or not it should accept an offered message.

See also
Scheduler Class, ScheduleGroup Class
9209  : _M_messageArray(_NumInputs),
9210  _M_savedMessageIdArray(_NumInputs)
9211  {
9212  _Initialize(_NumInputs);
9213  register_filter(_Filter);
9214  }
_MessageArray _M_messageArray
Definition: agents.h:9925
void _Initialize(size_t _NumInputs, Scheduler *_PScheduler=NULL, ScheduleGroup *_PScheduleGroup=NULL)
Initializes the join messaging block.
Definition: agents.h:9856
void register_filter(filter_method const &_Filter)
Registers a filter method that will be invoked on every received message.
Definition: agents.h:5841
_SavedMessageIdArray _M_savedMessageIdArray
Definition: agents.h:9950
template<class _Type , join_type _Jtype = non_greedy>
Concurrency::join< _Type, _Jtype >::~join ( )
inline

Destroys the join block.

9337  {
9338  // Remove all links that are targets of this join
9339  this->remove_network_links();
9340 
9341  // Clean up any messages left in this message block
9343 
9344  delete [] _M_savedIdBuffer;
9345  }
runtime_object_identity * _M_savedIdBuffer
Definition: agents.h:9953
void _Delete_stored_messages()
Deletes all messages currently stored in this message block. Should be called by the destructor to en...
Definition: agents.h:9882
void remove_network_links()
Removes all the source and target network links from this propagator_block object.
Definition: agents.h:5865

Member Function Documentation

template<class _Type , join_type _Jtype = non_greedy>
message<std::vector<_Type> >* __cdecl Concurrency::join< _Type, _Jtype >::_Create_new_message ( )
inlineprivate

Constructs a new message from the data output.

Returns
The created message (NULL if creation failed)
9744  {
9745  bool fIsNonGreedy = (_Jtype == non_greedy);
9746 
9747  // If this is a non-greedy join, check each source and try to consume their message
9748  if (fIsNonGreedy)
9749  {
9750 
9751  // The iterator _Iter below will ensure that it is safe to touch
9752  // non-NULL source pointers. Take a snapshot.
9753  std::vector<ISource<_Type> *> _Sources;
9754  source_iterator _Iter = this->_M_connectedSources.begin();
9755 
9756  while (*_Iter != NULL)
9757  {
9758  ISource<_Type> * _PSource = *_Iter;
9759 
9760  if (_PSource == NULL)
9761  {
9762  break;
9763  }
9764 
9765  _Sources.push_back(_PSource);
9766  ++_Iter;
9767  }
9768 
9769  if (_Sources.size() != _M_messageArray._M_count)
9770  {
9771  // Some of the sources were unlinked. The join is broken
9772  return NULL;
9773  }
9774 
9775  // First, try and reserve all the messages. If a reservation fails,
9776  // then release any reservations that had been made.
9777  for (size_t i = 0; i < _M_savedMessageIdArray._M_count; i++)
9778  {
9779  // Snap the current saved ID into a buffer. This value can be changing behind the scenes from
9780  // other source->propagate(msg, this) calls, but if so, that just means the reserve below will
9781  // fail.
9783  _M_savedIdBuffer[i] = _InterlockedExchange((volatile long *) &_M_savedMessageIdArray._M_savedIds[i], -1);
9784 
9786 
9787  if (!_Sources[i]->reserve(_M_savedIdBuffer[i], this))
9788  {
9789  // A reservation failed, release all reservations made up until
9790  // this block, and wait for another message to arrive on this link
9791  for (size_t j = 0; j < i; j++)
9792  {
9793  _Sources[j]->release(_M_savedIdBuffer[j], this);
9794  if (_InterlockedCompareExchange((volatile long *) &_M_savedMessageIdArray._M_savedIds[j], _M_savedIdBuffer[j], -1) == -1)
9795  {
9797  {
9798  this->async_send(NULL);
9799  }
9800  }
9801  }
9802 
9803  // Return NULL to indicate that the create failed
9804  return NULL;
9805  }
9806  }
9807 
9808  // Because everything has been reserved, consume all the messages.
9809  // This is guaranteed to return true.
9810  for (size_t i = 0; i < _M_messageArray._M_count; i++)
9811  {
9812  _M_messageArray._M_messages[i] = _Sources[i]->consume(_M_savedIdBuffer[i], this);
9813  _M_savedIdBuffer[i] = -1;
9814  }
9815  }
9816 
9817  if (!fIsNonGreedy)
9818  {
9819  // Reinitialize how many messages are being waited for.
9820  // This is safe because all messages have been received, thus no new async_sends for
9821  // greedy joins can be called.
9823  }
9824 
9825  std::vector<_Type> _OutputVector;
9826  for (size_t i = 0; i < _M_messageArray._M_count; i++)
9827  {
9829  _OutputVector.push_back(_M_messageArray._M_messages[i]->payload);
9830 
9831  delete _M_messageArray._M_messages[i];
9832  if (fIsNonGreedy)
9833  {
9835  }
9836  }
9837  return (new message<std::vector<_Type>>(_OutputVector));
9838  }
#define NULL
Definition: vcruntime.h:236
_MessageArray _M_messageArray
Definition: agents.h:9925
Non-greedy join messaging blocks postpone messages and try and consume them after all have arrived...
Definition: agents.h:9130
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
runtime_object_identity * _M_savedIds
Definition: agents.h:9936
size_t _M_count
Definition: agents.h:9935
#define _InterlockedDecrementSizeT(_Target)
Definition: concrt.h:97
int i[4]
Definition: dvec.h:68
message< _Type > ** _M_messages
Definition: agents.h:9909
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:5883
volatile size_t _M_messagesRemaining
Definition: agents.h:9902
_SourceLinkManager::iterator source_iterator
The type of the iterator for the source_link_manager for this propagator_block.
Definition: agents.h:5596
runtime_object_identity * _M_savedIdBuffer
Definition: agents.h:9953
size_t _M_count
Definition: agents.h:9908
_SavedMessageIdArray _M_savedMessageIdArray
Definition: agents.h:9950
virtual bool reserve(runtime_object_identity _MsgId, _Inout_ ITarget< _Target_type > *_PTarget)
Reserves a message previously offered by this source_block object.
Definition: agents.h:5052
long __cdecl _InterlockedCompareExchange(long volatile *, long, long)
virtual void async_send(_Inout_opt_ message< _Target_type > *_Msg)
Asynchronously queues up messages and starts a propagation task, if this has not been done already ...
Definition: agents.h:5434
#define _InterlockedIncrementSizeT(_Target)
Definition: concrt.h:96
template<class _Type , join_type _Jtype = non_greedy>
void Concurrency::join< _Type, _Jtype >::_Delete_stored_messages ( )
inlineprivate

Deletes all messages currently stored in this message block. Should be called by the destructor to ensure any messages propagated in are cleaned up.

9883  {
9884  // Input messages for this message block are in the base-class input buffer
9885  // All messages in that buffer are guaranteed to have moved to the output
9886  // buffer because the destructor first waits for all async sends to finish
9887  // before reaching this point
9888 
9889  // Delete any messages remaining in the output queue
9890  for (;;)
9891  {
9892  message<std::vector<_Type>> * _Msg = _M_messageBuffer._Dequeue();
9893  if (_Msg == NULL)
9894  {
9895  break;
9896  }
9897  delete _Msg;
9898  }
9899  }
#define NULL
Definition: vcruntime.h:236
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:9959
template<class _Type , join_type _Jtype = non_greedy>
void Concurrency::join< _Type, _Jtype >::_Initialize ( size_t  _NumInputs,
Scheduler *  _PScheduler = NULL,
ScheduleGroup *  _PScheduleGroup = NULL 
)
inlineprivate

Initializes the join messaging block.

Parameters
_NumInputsThe number of inputs.
_PSchedulerThe scheduler onto which the task to propagate the join block's message will be scheduled. If unspecified, the join messaging block uses the default scheduler.
_PScheduleGroupThe schedule group into which the task to propagate the join block's message will be scheduled. The scheduler used is implied by the schedule group. If unspecified, the join uses a schedule group of the scheduler's choosing.
9857  {
9858  this->initialize_source_and_target(_PScheduler, _PScheduleGroup);
9859 
9860  this->_M_connectedSources.set_bound(_NumInputs);
9861  _M_messagesRemaining = _NumInputs;
9862 
9863  bool fIsNonGreedy = (_Jtype == non_greedy);
9864 
9865  if (fIsNonGreedy)
9866  {
9867  // Non greedy joins need a buffer to snap off saved message IDs to.
9868  _M_savedIdBuffer = new runtime_object_identity[_NumInputs];
9869  memset(_M_savedIdBuffer, -1, sizeof(runtime_object_identity) * _NumInputs);
9870  }
9871  else
9872  {
9874  }
9875  }
#define NULL
Definition: vcruntime.h:236
Non-greedy join messaging blocks postpone messages and try and consume them after all have arrived...
Definition: agents.h:9130
__int32 runtime_object_identity
Each message instance has an identity that follows it as it is cloned and passed between messaging co...
Definition: agents.h:51
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:5883
volatile size_t _M_messagesRemaining
Definition: agents.h:9902
runtime_object_identity * _M_savedIdBuffer
Definition: agents.h:9953
void initialize_source_and_target(_Inout_opt_ Scheduler *_PScheduler=NULL, _Inout_opt_ ScheduleGroup *_PScheduleGroup=NULL)
Initializes the base object. Specifically, the message_processor object needs to be initialized...
Definition: agents.h:5826
template<class _Type , join_type _Jtype = non_greedy>
void Concurrency::join< _Type, _Jtype >::_Propagate_priority_order ( ::Concurrency::details::_Queue< message< _Target_type >> &  _MessageBuffer)
inlineprivate

Propagate messages in priority order.

Parameters
_MessageBufferReference to a message queue with messages to be propagated
9689  {
9690  message<_Target_type> * _Msg = _MessageBuffer._Peek();
9691 
9692  // If someone has reserved the _Head message, don't propagate anymore
9693  if (this->_M_pReservedFor != NULL)
9694  {
9695  return;
9696  }
9697 
9698  while (_Msg != NULL)
9699  {
9700  message_status _Status = declined;
9701 
9702  // Always start from the first target that linked
9703  for (target_iterator _Iter = this->_M_connectedTargets.begin(); *_Iter != NULL; ++_Iter)
9704  {
9705  ITarget<_Target_type> * _PTarget = *_Iter;
9706  _Status = _PTarget->propagate(_Msg, this);
9707 
9708  // Ownership of message changed. Do not propagate this
9709  // message to any other target.
9710  if (_Status == accepted)
9711  {
9712  break;
9713  }
9714 
9715  // If the target just propagated to reserved this message, stop
9716  // propagating it to others
9717  if (this->_M_pReservedFor != NULL)
9718  {
9719  break;
9720  }
9721  }
9722 
9723  // If status is anything other than accepted, then the head message
9724  // was not propagated out. Thus, nothing after it in the queue can
9725  // be propagated out. Cease propagation.
9726  if (_Status != accepted)
9727  {
9728  break;
9729  }
9730 
9731  // Get the next message
9732  _Msg = _MessageBuffer._Peek();
9733  }
9734  }
_Message * _Peek()
Definition: agents.h:227
single_link_registry< ITarget< std::vector< _Type > > >::iterator target_iterator
The iterator to walk the connected targets.
Definition: agents.h:4893
#define NULL
Definition: vcruntime.h:236
single_link_registry< ITarget< std::vector< _Type > > > _M_connectedTargets
Connected targets
Definition: agents.h:5484
The target did not accept the message.
Definition: agents.h:1751
message_status
The valid responses for an offer of a message object to a block.
Definition: agents.h:1740
The target accepted the message.
Definition: agents.h:1746
ITarget< _Target_type > * _M_pReservedFor
Connected target that is holding a reservation
Definition: agents.h:5472
template<class _Type , join_type _Jtype = non_greedy>
virtual message<_OutputType>* Concurrency::join< _Type, _Jtype >::accept_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Accepts a message that was offered by this join messaging block, transferring ownership to the caller.

Parameters
_MsgIdThe runtime_object_identity of the offered message object.
Returns
A pointer to the message object that the caller now has ownership of.

Implements Concurrency::source_block< single_link_registry< ITarget< std::vector< _Type > > >, _MessageProcessorType >.

9471  {
9472  //
9473  // Peek at the head message in the message buffer. If the IDs match
9474  // dequeue and transfer ownership
9475  //
9476  message<_OutputType> * _Msg = NULL;
9477 
9478  if (_M_messageBuffer._Is_head(_MsgId))
9479  {
9480  _Msg = _M_messageBuffer._Dequeue();
9481  }
9482 
9483  return _Msg;
9484  }
#define NULL
Definition: vcruntime.h:236
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:9959
template<class _Type , join_type _Jtype = non_greedy>
virtual message<_OutputType>* Concurrency::join< _Type, _Jtype >::consume_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Consumes a message previously offered by the join messaging block and reserved by the target, transferring ownership to the caller.

Parameters
_MsgIdThe runtime_object_identity of the message object being consumed.
Returns
A pointer to the message object that the caller now has ownership of.

Similar to accept, but is always preceded by a call to reserve.

Implements Concurrency::source_block< single_link_registry< ITarget< std::vector< _Type > > >, _MessageProcessorType >.

9521  {
9522  // By default, accept the message
9523  return accept_message(_MsgId);
9524  }
virtual message< _OutputType > * accept_message(runtime_object_identity _MsgId)
Accepts a message that was offered by this join messaging block, transferring ownership to the caller...
Definition: agents.h:9470
template<class _Type , join_type _Jtype = non_greedy>
virtual void Concurrency::join< _Type, _Jtype >::link_target_notification ( _Inout_ ITarget< std::vector< _Type >> *  )
inlineprotectedvirtual

A callback that notifies that a new target has been linked to this join messaging block.

Parameters
_PTargetA pointer to the newly linked target.
9563  {
9564  // If the message queue is blocked due to reservation
9565  // there is no need to do any message propagation
9566  if (this->_M_pReservedFor != NULL)
9567  {
9568  return;
9569  }
9570 
9572  }
void _Propagate_priority_order(::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
Propagate messages in priority order.
Definition: agents.h:9688
#define NULL
Definition: vcruntime.h:236
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:9959
ITarget< _Target_type > * _M_pReservedFor
Connected target that is holding a reservation
Definition: agents.h:5472
template<class _Type , join_type _Jtype = non_greedy>
message_status Concurrency::join< _Type, _Jtype >::propagate_message ( _Inout_ message< _Type > *  _PMessage,
_Inout_ ISource< _Type > *  _PSource 
)
inlineprotected

Asynchronously passes a message from an ISource block to this join messaging block. It is invoked by the propagate method, when called by a source block.

Parameters
_PMessageA pointer to the message object.
_PSourceA pointer to the source block offering the message.
Returns
A message_status indication of what the target decided to do with the message.
9368  {
9369  // It is important that calls to propagate do *not* take the same lock on the
9370  // internal structure that is used by Consume and the LWT. Doing so could
9371  // result in a deadlock with the Consume call.
9372 
9373  message_status _Ret_val = accepted;
9374 
9375  //
9376  // Find the slot index of this source
9377  //
9378  size_t _Slot = 0;
9379  bool _Found = false;
9380  for (source_iterator _Iter = this->_M_connectedSources.begin(); *_Iter != NULL; ++_Iter)
9381  {
9382  if (*_Iter == _PSource)
9383  {
9384  _Found = true;
9385  break;
9386  }
9387 
9388  _Slot++;
9389  }
9390 
9391  if (!_Found)
9392  {
9393  // If this source was not found in the array, this is not a connected source
9394  // decline the message
9395  return declined;
9396  }
9397 
9399 
9400  bool fIsGreedy = (_Jtype == greedy);
9401 
9402  if (fIsGreedy)
9403  {
9404  //
9405  // Greedy type joins immediately accept the message.
9406  //
9407  {
9408  _NR_lock lockHolder(_M_propagationLock);
9409  if (_M_messageArray._M_messages[_Slot] != NULL)
9410  {
9411  _M_savedMessageIdArray._M_savedIds[_Slot] = _PMessage->msg_id();
9412  _Ret_val = postponed;
9413  }
9414  }
9415 
9416  if (_Ret_val != postponed)
9417  {
9418  _M_messageArray._M_messages[_Slot] = _PSource->accept(_PMessage->msg_id(), this);
9419 
9420  if (_M_messageArray._M_messages[_Slot] != NULL)
9421  {
9423  {
9424  // If messages have arrived on all links, start a propagation
9425  // of the current message
9426  this->async_send(NULL);
9427  }
9428  }
9429  else
9430  {
9431  _Ret_val = missed;
9432  }
9433  }
9434  }
9435  else
9436  {
9437  //
9438  // Non-greedy type joins save the message IDs until they have all arrived
9439  //
9440 
9441  if (_InterlockedExchange((volatile long *) &_M_savedMessageIdArray._M_savedIds[_Slot], _PMessage->msg_id()) == -1)
9442  {
9443  // Decrement the message remaining count if this thread is switching
9444  // the saved ID from -1 to a valid value.
9446  {
9447  this->async_send(NULL);
9448  }
9449  }
9450 
9451  // Always return postponed. This message will be consumed
9452  // in the LWT
9453  _Ret_val = postponed;
9454  }
9455 
9456  return _Ret_val;
9457  }
#define NULL
Definition: vcruntime.h:236
_MessageArray _M_messageArray
Definition: agents.h:9925
#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
runtime_object_identity * _M_savedIds
Definition: agents.h:9936
#define _InterlockedDecrementSizeT(_Target)
Definition: concrt.h:97
message_status
The valid responses for an offer of a message object to a block.
Definition: agents.h:1740
The target tried to accept the message, but it was no longer available.
Definition: agents.h:1761
message< _Type > ** _M_messages
Definition: agents.h:9909
The target accepted the message.
Definition: agents.h:1746
::Concurrency::details::_NonReentrantPPLLock::_Scoped_lock _NR_lock
A lock holder that acquires a non-reentrant lock on instantiation and releases it on destruction...
Definition: agents.h:58
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:5883
volatile size_t _M_messagesRemaining
Definition: agents.h:9902
_SourceLinkManager::iterator source_iterator
The type of the iterator for the source_link_manager for this propagator_block.
Definition: agents.h:5596
size_t _M_count
Definition: agents.h:9908
_SavedMessageIdArray _M_savedMessageIdArray
Definition: agents.h:9950
::Concurrency::details::_NonReentrantPPLLock _M_propagationLock
Definition: agents.h:9956
Greedy join messaging blocks immediately accept a message upon propagation. This is more efficient...
Definition: agents.h:9124
virtual void async_send(_Inout_opt_ message< _Target_type > *_Msg)
Asynchronously queues up messages and starts a propagation task, if this has not been done already ...
Definition: agents.h:5434
template<class _Type , join_type _Jtype = non_greedy>
void Concurrency::join< _Type, _Jtype >::propagate_to_any_targets ( _Inout_opt_ message< _OutputType > *  )
inlineprotected

Constructs an output message containing an input message from each source when they have all propagated a message. Sends this output message out to each of its targets.

9581  {
9582  message<_OutputType> * _Msg = NULL;
9583  // Create a new message from the input sources
9584  // If messagesRemaining == 0, we have a new message to create. Otherwise, this is coming from
9585  // a consume or release from the target. In that case we don't want to create a new message.
9586  if (_M_messagesRemaining == 0)
9587  {
9588  // A greedy join can immediately create the message, a non-greedy
9589  // join must try and consume all the messages it has postponed
9590  _Msg = _Create_new_message();
9591  }
9592 
9593  if (_Msg == NULL)
9594  {
9595  // Create message failed. This happens in non_greedy joins when the
9596  // reserve/consumption of a postponed message failed.
9598  return;
9599  }
9600 
9601  bool fIsGreedy = (_Jtype == greedy);
9602 
9603  // For a greedy join, reset the number of messages remaining
9604  // Check to see if multiple messages have been passed in on any of the links,
9605  // and postponed. If so, try and reserve/consume them now
9606  if (fIsGreedy)
9607  {
9608  // Look at the saved IDs and reserve/consume any that have passed in while
9609  // this join was waiting to complete
9611 
9612  for (size_t i = 0; i < _M_messageArray._M_count; i++)
9613  {
9614  for(;;)
9615  {
9616  runtime_object_identity _Saved_id;
9617  // Grab the current saved ID value. This value could be changing from based on any
9618  // calls of source->propagate(this). If the message ID is different than what is snapped
9619  // here, that means, the reserve below must fail. This is because reserve is trying
9620  // to get the same source lock the propagate(this) call must be holding.
9621  {
9622  _NR_lock lockHolder(_M_propagationLock);
9623 
9625 
9626  _Saved_id = _M_savedMessageIdArray._M_savedIds[i];
9627 
9628  if (_Saved_id == -1)
9629  {
9631  break;
9632  }
9633  else
9634  {
9636  }
9637  }
9638 
9639  if (_Saved_id != -1)
9640  {
9641  source_iterator _Iter = this->_M_connectedSources.begin();
9642 
9643  ISource<_Type> * _PSource = _Iter[i];
9644  if ((_PSource != NULL) && _PSource->reserve(_Saved_id, this))
9645  {
9646  _M_messageArray._M_messages[i] = _PSource->consume(_Saved_id, this);
9648  break;
9649  }
9650  }
9651  }
9652  }
9653 
9654  // If messages have all been received, async_send again, this will start the
9655  // LWT up to create a new message
9656  if (_M_messagesRemaining == 0)
9657  {
9658  this->async_send(NULL);
9659  }
9660  }
9661 
9662  // Add the new message to the outbound queue
9663  _M_messageBuffer._Enqueue(_Msg);
9664 
9665  if (!_M_messageBuffer._Is_head(_Msg->msg_id()))
9666  {
9667  // another message is at the head of the outbound message queue and blocked
9668  // simply return
9669  return;
9670  }
9671 
9673  }
void _Propagate_priority_order(::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
Propagate messages in priority order.
Definition: agents.h:9688
#define NULL
Definition: vcruntime.h:236
_MessageArray _M_messageArray
Definition: agents.h:9925
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
__int32 runtime_object_identity
Each message instance has an identity that follows it as it is cloned and passed between messaging co...
Definition: agents.h:51
message< std::vector< _Type > > *__cdecl _Create_new_message()
Constructs a new message from the data output.
Definition: agents.h:9743
runtime_object_identity * _M_savedIds
Definition: agents.h:9936
size_t _M_count
Definition: agents.h:9935
#define _InterlockedDecrementSizeT(_Target)
Definition: concrt.h:97
int i[4]
Definition: dvec.h:68
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:9959
message< _Type > ** _M_messages
Definition: agents.h:9909
::Concurrency::details::_NonReentrantPPLLock::_Scoped_lock _NR_lock
A lock holder that acquires a non-reentrant lock on instantiation and releases it on destruction...
Definition: agents.h:58
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:5883
volatile size_t _M_messagesRemaining
Definition: agents.h:9902
_SourceLinkManager::iterator source_iterator
The type of the iterator for the source_link_manager for this propagator_block.
Definition: agents.h:5596
size_t _M_count
Definition: agents.h:9908
_SavedMessageIdArray _M_savedMessageIdArray
Definition: agents.h:9950
::Concurrency::details::_NonReentrantPPLLock _M_propagationLock
Definition: agents.h:9956
Greedy join messaging blocks immediately accept a message upon propagation. This is more efficient...
Definition: agents.h:9124
virtual void async_send(_Inout_opt_ message< _Target_type > *_Msg)
Asynchronously queues up messages and starts a propagation task, if this has not been done already ...
Definition: agents.h:5434
template<class _Type , join_type _Jtype = non_greedy>
virtual void Concurrency::join< _Type, _Jtype >::release_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Releases a previous message reservation.

Parameters
_MsgIdThe runtime_object_identity of the message object being released.

Implements Concurrency::source_block< single_link_registry< ITarget< std::vector< _Type > > >, _MessageProcessorType >.

9534  {
9535  // The head message is the one reserved.
9536  if (!_M_messageBuffer._Is_head(_MsgId))
9537  {
9538  throw message_not_found();
9539  }
9540  }
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:9959
template<class _Type , join_type _Jtype = non_greedy>
virtual bool Concurrency::join< _Type, _Jtype >::reserve_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Reserves a message previously offered by this join messaging block.

Parameters
_MsgIdThe runtime_object_identity of the offered message object.
Returns
true if the message was successfully reserved, false otherwise.

After reserve is called, if it returns true, either consume or release must be called to either take or release ownership of the message.

Implements Concurrency::source_block< single_link_registry< ITarget< std::vector< _Type > > >, _MessageProcessorType >.

9501  {
9502  // Allow reservation if this is the head message
9503  return _M_messageBuffer._Is_head(_MsgId);
9504  }
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:9959
template<class _Type , join_type _Jtype = non_greedy>
virtual void Concurrency::join< _Type, _Jtype >::resume_propagation ( )
inlineprotectedvirtual

Resumes propagation after a reservation has been released.

Implements Concurrency::source_block< single_link_registry< ITarget< std::vector< _Type > > >, _MessageProcessorType >.

9547  {
9548  // If there are any messages in the buffer, propagate them out
9549  if (_M_messageBuffer._Count() > 0)
9550  {
9551  this->async_send(NULL);
9552  }
9553  }
#define NULL
Definition: vcruntime.h:236
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:9959
virtual void async_send(_Inout_opt_ message< _Target_type > *_Msg)
Asynchronously queues up messages and starts a propagation task, if this has not been done already ...
Definition: agents.h:5434

Member Data Documentation

template<class _Type , join_type _Jtype = non_greedy>
_MessageArray Concurrency::join< _Type, _Jtype >::_M_messageArray
private
template<class _Type , join_type _Jtype = non_greedy>
::Concurrency::details::_Queue<message<std::vector<_Type> > > Concurrency::join< _Type, _Jtype >::_M_messageBuffer
private
template<class _Type , join_type _Jtype = non_greedy>
volatile size_t Concurrency::join< _Type, _Jtype >::_M_messagesRemaining
private
template<class _Type , join_type _Jtype = non_greedy>
::Concurrency::details::_NonReentrantPPLLock Concurrency::join< _Type, _Jtype >::_M_propagationLock
private
template<class _Type , join_type _Jtype = non_greedy>
runtime_object_identity* Concurrency::join< _Type, _Jtype >::_M_savedIdBuffer
private
template<class _Type , join_type _Jtype = non_greedy>
_SavedMessageIdArray Concurrency::join< _Type, _Jtype >::_M_savedMessageIdArray
private

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