STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Types | Public Member Functions | Protected Member Functions | 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::tr1::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 sourse 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 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

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
7483  : _M_messageArray(_NumInputs),
7484  _M_savedMessageIdArray(_NumInputs)
7485  {
7486  _Initialize(_NumInputs);
7487  }
_MessageArray _M_messageArray
Definition: agents.h:8225
void _Initialize(size_t _NumInputs, Scheduler *_PScheduler=NULL, ScheduleGroup *_PScheduleGroup=NULL)
Initializes the join messaging block.
Definition: agents.h:8156
_SavedMessageIdArray _M_savedMessageIdArray
Definition: agents.h:8250
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
7509  : _M_messageArray(_NumInputs),
7510  _M_savedMessageIdArray(_NumInputs)
7511  {
7512  _Initialize(_NumInputs);
7513  register_filter(_Filter);
7514  }
_MessageArray _M_messageArray
Definition: agents.h:8225
void _Initialize(size_t _NumInputs, Scheduler *_PScheduler=NULL, ScheduleGroup *_PScheduleGroup=NULL)
Initializes the join messaging block.
Definition: agents.h:8156
void register_filter(filter_method const &_Filter)
Registers a filter method that will be invoked on every received message.
Definition: agents.h:4188
_SavedMessageIdArray _M_savedMessageIdArray
Definition: agents.h:8250
template<class _Type , join_type _Jtype = non_greedy>
Concurrency::join< _Type, _Jtype >::~join ( )
inline

Destroys the join block.

7637  {
7638  // Remove all links that are targets of this join
7640 
7641  // Clean up any messages left in this message block
7643 
7644  delete [] _M_savedIdBuffer;
7645  }
runtime_object_identity * _M_savedIdBuffer
Definition: agents.h:8253
void _Delete_stored_messages()
Deletes all messages currently stored in this message block. Should be called by the destructor to en...
Definition: agents.h:8182
void remove_network_links()
Removes all the source and target network links from this propagator_block object.
Definition: agents.h:4212

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)
8044  {
8045  bool fIsNonGreedy = (_Jtype == non_greedy);
8046 
8047  // If this is a non-greedy join, check each source and try to consume their message
8048  if (fIsNonGreedy)
8049  {
8050 
8051  // The iterator _Iter below will ensure that it is safe to touch
8052  // non-NULL source pointers. Take a snapshot.
8053  std::vector<ISource<_Type> *> _Sources;
8055 
8056  while (*_Iter != NULL)
8057  {
8058  ISource<_Type> * _PSource = *_Iter;
8059 
8060  if (_PSource == NULL)
8061  {
8062  break;
8063  }
8064 
8065  _Sources.push_back(_PSource);
8066  ++_Iter;
8067  }
8068 
8069  if (_Sources.size() != _M_messageArray._M_count)
8070  {
8071  // Some of the sources were unlinked. The join is broken
8072  return NULL;
8073  }
8074 
8075  // First, try and reserve all the messages. If a reservation fails,
8076  // then release any reservations that had been made.
8077  for (size_t i = 0; i < _M_savedMessageIdArray._M_count; i++)
8078  {
8079  // Snap the current saved ID into a buffer. This value can be changing behind the scenes from
8080  // other source->propagate(msg, this) calls, but if so, that just means the reserve below will
8081  // fail.
8083  _M_savedIdBuffer[i] = _InterlockedExchange((volatile long *) &_M_savedMessageIdArray._M_savedIds[i], -1);
8084 
8086 
8087  if (!_Sources[i]->reserve(_M_savedIdBuffer[i], this))
8088  {
8089  // A reservation failed, release all reservations made up until
8090  // this block, and wait for another message to arrive on this link
8091  for (size_t j = 0; j < i; j++)
8092  {
8093  _Sources[j]->release(_M_savedIdBuffer[j], this);
8094  if (_InterlockedCompareExchange((volatile long *) &_M_savedMessageIdArray._M_savedIds[j], _M_savedIdBuffer[j], -1) == -1)
8095  {
8097  {
8098  async_send(NULL);
8099  }
8100  }
8101  }
8102 
8103  // Return NULL to indicate that the create failed
8104  return NULL;
8105  }
8106  }
8107 
8108  // Because everything has been reserved, consume all the messages.
8109  // This is guaranteed to return true.
8110  for (size_t i = 0; i < _M_messageArray._M_count; i++)
8111  {
8112  _M_messageArray._M_messages[i] = _Sources[i]->consume(_M_savedIdBuffer[i], this);
8113  _M_savedIdBuffer[i] = -1;
8114  }
8115  }
8116 
8117  if (!fIsNonGreedy)
8118  {
8119  // Reinitialize how many messages are being waited for.
8120  // This is safe because all messages have been received, thus no new async_sends for
8121  // greedy joins can be called.
8123  }
8124 
8125  std::vector<_Type> _OutputVector;
8126  for (size_t i = 0; i < _M_messageArray._M_count; i++)
8127  {
8129  _OutputVector.push_back(_M_messageArray._M_messages[i]->payload);
8130 
8131  delete _M_messageArray._M_messages[i];
8132  if (fIsNonGreedy)
8133  {
8135  }
8136  }
8137  return (new message<std::vector<_Type>>(_OutputVector));
8138  }
_MessageArray _M_messageArray
Definition: agents.h:8225
Non-greedy join messaging blocks postpone messages and try and consume them after all have arrived...
Definition: agents.h:7439
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
#define NULL
Definition: crtdbg.h:30
runtime_object_identity * _M_savedIds
Definition: agents.h:8236
size_t _M_count
Definition: agents.h:8235
#define _InterlockedDecrementSizeT(_Target)
Definition: concrt.h:111
int i[4]
Definition: dvec.h:70
message< _Type > ** _M_messages
Definition: agents.h:8209
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:4230
volatile size_t _M_messagesRemaining
Definition: agents.h:8202
_SourceLinkManager::iterator source_iterator
The type of the iterator for the source_link_manager for this propagator_block.
Definition: agents.h:3946
runtime_object_identity * _M_savedIdBuffer
Definition: agents.h:8253
size_t _M_count
Definition: agents.h:8208
_SavedMessageIdArray _M_savedMessageIdArray
Definition: agents.h:8250
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:3401
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:3783
#define _InterlockedIncrementSizeT(_Target)
Definition: concrt.h:110
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.

8183  {
8184  // Input messages for this message block are in the base-class input buffer
8185  // All messages in that buffer are guaranteed to have moved to the output
8186  // buffer because the destructor first waits for all async sends to finish
8187  // before reaching this point
8188 
8189  // Delete any messages remaining in the output queue
8190  for (;;)
8191  {
8192  message<std::vector<_Type>> * _Msg = _M_messageBuffer._Dequeue();
8193  if (_Msg == NULL)
8194  {
8195  break;
8196  }
8197  delete _Msg;
8198  }
8199  }
#define NULL
Definition: crtdbg.h:30
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:8259
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.
8157  {
8158  initialize_source_and_target(_PScheduler, _PScheduleGroup);
8159 
8160  _M_connectedSources.set_bound(_NumInputs);
8161  _M_messagesRemaining = _NumInputs;
8162 
8163  bool fIsNonGreedy = (_Jtype == non_greedy);
8164 
8165  if (fIsNonGreedy)
8166  {
8167  // Non greedy joins need a buffer to snap off saved message IDs to.
8168  _M_savedIdBuffer = new runtime_object_identity[_NumInputs];
8169  memset(_M_savedIdBuffer, -1, sizeof(runtime_object_identity) * _NumInputs);
8170  }
8171  else
8172  {
8174  }
8175  }
Non-greedy join messaging blocks postpone messages and try and consume them after all have arrived...
Definition: agents.h:7439
#define NULL
Definition: crtdbg.h:30
__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:50
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:4230
volatile size_t _M_messagesRemaining
Definition: agents.h:8202
runtime_object_identity * _M_savedIdBuffer
Definition: agents.h:8253
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:4173
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
7989  {
7990  message<_Target_type> * _Msg = _MessageBuffer._Peek();
7991 
7992  // If someone has reserved the _Head message, don't propagate anymore
7993  if (_M_pReservedFor != NULL)
7994  {
7995  return;
7996  }
7997 
7998  while (_Msg != NULL)
7999  {
8000  message_status _Status = declined;
8001 
8002  // Always start from the first target that linked
8003  for (target_iterator _Iter = _M_connectedTargets.begin(); *_Iter != NULL; ++_Iter)
8004  {
8005  ITarget<_Target_type> * _PTarget = *_Iter;
8006  _Status = _PTarget->propagate(_Msg, this);
8007 
8008  // Ownership of message changed. Do not propagate this
8009  // message to any other target.
8010  if (_Status == accepted)
8011  {
8012  break;
8013  }
8014 
8015  // If the target just propagated to reserved this message, stop
8016  // propagating it to others
8017  if (_M_pReservedFor != NULL)
8018  {
8019  break;
8020  }
8021  }
8022 
8023  // If status is anything other than accepted, then the head message
8024  // was not propagated out. Thus, nothing after it in the queue can
8025  // be propagated out. Cease propagation.
8026  if (_Status != accepted)
8027  {
8028  break;
8029  }
8030 
8031  // Get the next message
8032  _Msg = _MessageBuffer._Peek();
8033  }
8034  }
_Message * _Peek()
Definition: agents.h:226
single_link_registry< ITarget< std::vector< _Type > > >::iterator target_iterator
The iterator to walk the connected targets.
Definition: agents.h:3242
single_link_registry< ITarget< std::vector< _Type > > > _M_connectedTargets
Connected targets
Definition: agents.h:3833
The target did not accept the message.
Definition: agents.h:1750
#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
The target accepted the message.
Definition: agents.h:1745
ITarget< _Target_type > * _M_pReservedFor
Connected target that is holding a reservation
Definition: agents.h:3821
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 >.

7771  {
7772  //
7773  // Peek at the head message in the message buffer. If the IDs match
7774  // dequeue and transfer ownership
7775  //
7776  message<_OutputType> * _Msg = NULL;
7777 
7778  if (_M_messageBuffer._Is_head(_MsgId))
7779  {
7780  _Msg = _M_messageBuffer._Dequeue();
7781  }
7782 
7783  return _Msg;
7784  }
#define NULL
Definition: crtdbg.h:30
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:8259
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 >.

7821  {
7822  // By default, accept the message
7823  return accept_message(_MsgId);
7824  }
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:7770
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.
7863  {
7864  // If the message queue is blocked due to reservation
7865  // there is no need to do any message propagation
7866  if (_M_pReservedFor != NULL)
7867  {
7868  return;
7869  }
7870 
7872  }
void _Propagate_priority_order(::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
Propagate messages in priority order.
Definition: agents.h:7988
#define NULL
Definition: crtdbg.h:30
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:8259
ITarget< _Target_type > * _M_pReservedFor
Connected target that is holding a reservation
Definition: agents.h:3821
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.
7668  {
7669  // It is important that calls to propagate do *not* take the same lock on the
7670  // internal structure that is used by Consume and the LWT. Doing so could
7671  // result in a deadlock with the Consume call.
7672 
7673  message_status _Ret_val = accepted;
7674 
7675  //
7676  // Find the slot index of this source
7677  //
7678  size_t _Slot = 0;
7679  bool _Found = false;
7680  for (source_iterator _Iter = _M_connectedSources.begin(); *_Iter != NULL; ++_Iter)
7681  {
7682  if (*_Iter == _PSource)
7683  {
7684  _Found = true;
7685  break;
7686  }
7687 
7688  _Slot++;
7689  }
7690 
7691  if (!_Found)
7692  {
7693  // If this source was not found in the array, this is not a connected source
7694  // decline the message
7695  return declined;
7696  }
7697 
7699 
7700  bool fIsGreedy = (_Jtype == greedy);
7701 
7702  if (fIsGreedy)
7703  {
7704  //
7705  // Greedy type joins immediately accept the message.
7706  //
7707  {
7708  _NR_lock lockHolder(_M_propagationLock);
7709  if (_M_messageArray._M_messages[_Slot] != NULL)
7710  {
7711  _M_savedMessageIdArray._M_savedIds[_Slot] = _PMessage->msg_id();
7712  _Ret_val = postponed;
7713  }
7714  }
7715 
7716  if (_Ret_val != postponed)
7717  {
7718  _M_messageArray._M_messages[_Slot] = _PSource->accept(_PMessage->msg_id(), this);
7719 
7720  if (_M_messageArray._M_messages[_Slot] != NULL)
7721  {
7723  {
7724  // If messages have arrived on all links, start a propagation
7725  // of the current message
7726  async_send(NULL);
7727  }
7728  }
7729  else
7730  {
7731  _Ret_val = missed;
7732  }
7733  }
7734  }
7735  else
7736  {
7737  //
7738  // Non-greedy type joins save the message IDs until they have all arrived
7739  //
7740 
7741  if (_InterlockedExchange((volatile long *) &_M_savedMessageIdArray._M_savedIds[_Slot], _PMessage->msg_id()) == -1)
7742  {
7743  // Decrement the message remaining count if this thread is switching
7744  // the saved ID from -1 to a valid value.
7746  {
7747  async_send(NULL);
7748  }
7749  }
7750 
7751  // Always return postponed. This message will be consumed
7752  // in the LWT
7753  _Ret_val = postponed;
7754  }
7755 
7756  return _Ret_val;
7757  }
_MessageArray _M_messageArray
Definition: agents.h:8225
#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
runtime_object_identity * _M_savedIds
Definition: agents.h:8236
#define _InterlockedDecrementSizeT(_Target)
Definition: concrt.h:111
message_status
The valid responses for an offer of a message object to a block.
Definition: agents.h:1739
The target tried to accept the message, but it was no longer available.
Definition: agents.h:1760
message< _Type > ** _M_messages
Definition: agents.h:8209
The target accepted the message.
Definition: agents.h:1745
::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:57
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:4230
volatile size_t _M_messagesRemaining
Definition: agents.h:8202
_SourceLinkManager::iterator source_iterator
The type of the iterator for the source_link_manager for this propagator_block.
Definition: agents.h:3946
size_t _M_count
Definition: agents.h:8208
_SavedMessageIdArray _M_savedMessageIdArray
Definition: agents.h:8250
::Concurrency::details::_NonReentrantPPLLock _M_propagationLock
Definition: agents.h:8256
Greedy join messaging blocks immediately accept a message upon propagation. This is more efficient...
Definition: agents.h:7433
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:3783
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.

7881  {
7882  message<_OutputType> * _Msg = NULL;
7883  // Create a new message from the input sources
7884  // If messagesRemaining == 0, we have a new message to create. Otherwise, this is coming from
7885  // a consume or release from the target. In that case we don't want to create a new message.
7886  if (_M_messagesRemaining == 0)
7887  {
7888  // A greedy join can immediately create the message, a non-greedy
7889  // join must try and consume all the messages it has postponed
7890  _Msg = _Create_new_message();
7891  }
7892 
7893  if (_Msg == NULL)
7894  {
7895  // Create message failed. This happens in non_greedy joins when the
7896  // reserve/consumption of a postponed message failed.
7898  return;
7899  }
7900 
7901  bool fIsGreedy = (_Jtype == greedy);
7902 
7903  // For a greedy join, reset the number of messages remaining
7904  // Check to see if multiple messages have been passed in on any of the links,
7905  // and postponed. If so, try and reserve/consume them now
7906  if (fIsGreedy)
7907  {
7908  // Look at the saved IDs and reserve/consume any that have passed in while
7909  // this join was waiting to complete
7911 
7912  for (size_t i = 0; i < _M_messageArray._M_count; i++)
7913  {
7914  for(;;)
7915  {
7916  runtime_object_identity _Saved_id;
7917  // Grab the current saved ID value. This value could be changing from based on any
7918  // calls of source->propagate(this). If the message ID is different than what is snapped
7919  // here, that means, the reserve below must fail. This is because reserve is trying
7920  // to get the same source lock the propagate(this) call must be holding.
7921  {
7922  _NR_lock lockHolder(_M_propagationLock);
7923 
7925 
7926  _Saved_id = _M_savedMessageIdArray._M_savedIds[i];
7927 
7928  if (_Saved_id == -1)
7929  {
7931  break;
7932  }
7933  else
7934  {
7936  }
7937  }
7938 
7939  if (_Saved_id != -1)
7940  {
7942 
7943  ISource<_Type> * _PSource = _Iter[i];
7944  if ((_PSource != NULL) && _PSource->reserve(_Saved_id, this))
7945  {
7946  _M_messageArray._M_messages[i] = _PSource->consume(_Saved_id, this);
7948  break;
7949  }
7950  }
7951  }
7952  }
7953 
7954  // If messages have all been received, async_send again, this will start the
7955  // LWT up to create a new message
7956  if (_M_messagesRemaining == 0)
7957  {
7958  async_send(NULL);
7959  }
7960  }
7961 
7962  // Add the new message to the outbound queue
7963  _M_messageBuffer._Enqueue(_Msg);
7964 
7965  if (!_M_messageBuffer._Is_head(_Msg->msg_id()))
7966  {
7967  // another message is at the head of the outbound message queue and blocked
7968  // simply return
7969  return;
7970  }
7971 
7973  }
void _Propagate_priority_order(::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
Propagate messages in priority order.
Definition: agents.h:7988
_MessageArray _M_messageArray
Definition: agents.h:8225
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
#define NULL
Definition: crtdbg.h:30
__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:50
message< std::vector< _Type > > *__cdecl _Create_new_message()
Constructs a new message from the data output.
Definition: agents.h:8043
runtime_object_identity * _M_savedIds
Definition: agents.h:8236
size_t _M_count
Definition: agents.h:8235
#define _InterlockedDecrementSizeT(_Target)
Definition: concrt.h:111
int i[4]
Definition: dvec.h:70
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:8259
message< _Type > ** _M_messages
Definition: agents.h:8209
::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:57
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:4230
volatile size_t _M_messagesRemaining
Definition: agents.h:8202
_SourceLinkManager::iterator source_iterator
The type of the iterator for the source_link_manager for this propagator_block.
Definition: agents.h:3946
size_t _M_count
Definition: agents.h:8208
_SavedMessageIdArray _M_savedMessageIdArray
Definition: agents.h:8250
::Concurrency::details::_NonReentrantPPLLock _M_propagationLock
Definition: agents.h:8256
Greedy join messaging blocks immediately accept a message upon propagation. This is more efficient...
Definition: agents.h:7433
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:3783
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 >.

7834  {
7835  // The head message is the one reserved.
7836  if (!_M_messageBuffer._Is_head(_MsgId))
7837  {
7838  throw message_not_found();
7839  }
7840  }
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:8259
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 >.

7801  {
7802  // Allow reservation if this is the head message
7803  return _M_messageBuffer._Is_head(_MsgId);
7804  }
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:8259
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 >.

7847  {
7848  // If there are any messages in the buffer, propagate them out
7849  if (_M_messageBuffer._Count() > 0)
7850  {
7851  async_send(NULL);
7852  }
7853  }
#define NULL
Definition: crtdbg.h:30
::Concurrency::details::_Queue< message< std::vector< _Type > > > _M_messageBuffer
Definition: agents.h:8259
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:3783

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: