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

Defines a block allowing sources of distinct types to be joined. Join node is a single-target, multi-source ordered propagator block More...

#include <agents.h>

Inheritance diagram for Concurrency::_Join_node< _Type, _Destination_type, _Jtype >:
Concurrency::propagator_block< single_link_registry< ITarget< _Destination_type > >, multi_link_registry< ISource< size_t > > > Concurrency::source_block< single_link_registry< ITarget< _Destination_type > >, _MessageProcessorType > Concurrency::ITarget< multi_link_registry< ISource< size_t > >::type::source_type > Concurrency::ISource< single_link_registry< ITarget< _Destination_type > >::type::type >

Public Member Functions

 _Join_node ()
 Constructs a join within the default scheduler, and places it on any schedule group of the scheduler's choosing. More...
 
 _Join_node (Scheduler &_PScheduler)
 Constructs a join within the specified scheduler, and places it on any schedule group of the scheduler's choosing. More...
 
 _Join_node (ScheduleGroup &_PScheduleGroup)
 Constructs a join within the specified schedule group. The scheduler is implied by the schedule group. More...
 
 ~_Join_node ()
 Cleans up any resources that may have been created by the join. More...
 
- Public Member Functions inherited from Concurrency::propagator_block< single_link_registry< ITarget< _Destination_type > >, multi_link_registry< ISource< size_t > > >
 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< _Destination_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< _Destination_type > >::type::type >
virtual ~ISource ()
 Destroys the ISource object. More...
 
virtual void link_target (_Inout_ ITarget< single_link_registry< ITarget< _Destination_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< _Destination_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< _Destination_type > >::type::type > * accept (runtime_object_identity _MsgId, _Inout_ ITarget< single_link_registry< ITarget< _Destination_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< _Destination_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< _Destination_type > >::type::type > * consume (runtime_object_identity _MsgId, _Inout_ ITarget< single_link_registry< ITarget< _Destination_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< _Destination_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< _Destination_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< _Destination_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< size_t > >::type::source_type >
virtual ~ITarget ()
 Destroys the ITarget object. More...
 
virtual message_status propagate (_Inout_opt_ message< multi_link_registry< ISource< size_t > >::type::source_type > *_PMessage, _Inout_opt_ ISource< multi_link_registry< ISource< size_t > >::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< size_t > >::type::source_type > *_PMessage, _Inout_ ISource< multi_link_registry< ISource< size_t > >::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

virtual message_status propagate_message (message< size_t > *_PMessage, ISource< size_t > *_PSource)
 Asynchronously passes a message from an ISource block to this ITarget block. It is invoked by the propagate method, when called by a source block. More...
 
virtual message< _Destination_type > * accept_message (runtime_object_identity _MsgId)
 Accepts an offered message by the source, transferring ownership to the caller. More...
 
virtual bool reserve_message (runtime_object_identity _MsgId)
 Reserves a message previously offered by the source. More...
 
virtual message< _Destination_type > * consume_message (runtime_object_identity _MsgId)
 Consumes a message previously offered by the source 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< _Destination_type > *)
 Notification that a target was linked to this source. More...
 
virtual void propagate_to_any_targets (_Inout_opt_ message< _Destination_type > *)
 Takes the message and propagates it to all the targets of this join block. More...
 
- Protected Member Functions inherited from Concurrency::propagator_block< single_link_registry< ITarget< _Destination_type > >, multi_link_registry< ISource< size_t > > >
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< _Destination_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< _Destination_type > >::type::type >
void _Invoke_link_source (ITarget< single_link_registry< ITarget< _Destination_type > >::type::type > *_PLinkFrom)
 Links this source to a target. More...
 
void _Invoke_unlink_source (ITarget< single_link_registry< ITarget< _Destination_type > >::type::type > *_PUnlinkFrom)
 Unlinks this source from a target. More...
 
- Protected Member Functions inherited from Concurrency::ITarget< multi_link_registry< ISource< size_t > >::type::source_type >
virtual void link_source (_Inout_ ISource< multi_link_registry< ISource< size_t > >::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< size_t > >::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< _Destination_type > > _TargetLinkRegistry
 
typedef multi_link_registry< ISource< size_t > > _SourceLinkRegistry
 

Private Member Functions

template<int _Index>
bool _Try_consume_source_messages (_Destination_type &_Destination_tuple, ISource< size_t > **_Sources)
 Tries to reserve from all sources. If successful, it will consume all the messages More...
 
template<>
bool _Try_consume_source_messages (_Destination_type &, ISource< size_t > **)
 Provides a sentinel template specialization for _Try_consume_source_messages recursive template expansion. More...
 
bool _Non_greedy_acquire_messages ()
 Tries to acquire all of the messages from the _Non_greedy_nodes. Each node has already indicated that it has received a message that it can try to reserve. This function starts the reservation and consume process. More...
 
void _Propagate_priority_order (::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
 Propagate messages in priority order More...
 
message< _Destination_type > * _Create_send_message ()
 Called when all the source messaging blocks have received their messages. The payloads are copied into local tuple and then packaged into a message to be propagated: _M_pSendMessage. 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...
 
template<int _Index>
void _Populate_destination_tuple (_Destination_type &_Destination_tuple, ISource< size_t > **_Sources)
 Copies payloads from all sources to destination tuple. More...
 
template<>
void _Populate_destination_tuple (_Destination_type &, ISource< size_t > **)
 Provides a sentinel template specialization for _Populate_destination_tuple recursive template expansion. More...
 
 _Join_node (const _Join_node &_Join)
 
_Join_node const & operator= (_Join_node const &)
 

Private Attributes

_Type _M_sourceTuple
 
volatile long _M_counter
 
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
 

Additional Inherited Members

- Public Types inherited from Concurrency::propagator_block< single_link_registry< ITarget< _Destination_type > >, multi_link_registry< ISource< size_t > > >
typedef multi_link_registry< ISource< size_t > >::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< size_t > > > _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< _Destination_type > >, _MessageProcessorType >
typedef single_link_registry< ITarget< _Destination_type > >::type::type _Target_type
 The payload type of messages handled by this source_block. More...
 
typedef single_link_registry< ITarget< _Destination_type > >::iterator target_iterator
 The iterator to walk the connected targets. More...
 
- Public Types inherited from Concurrency::ISource< single_link_registry< ITarget< _Destination_type > >::type::type >
typedef single_link_registry< ITarget< _Destination_type > >::type::type source_type
 A type alias for _Type . More...
 
- Public Types inherited from Concurrency::ITarget< multi_link_registry< ISource< size_t > >::type::source_type >
typedef multi_link_registry< ISource< size_t > >::type::source_type type
 A type alias for _Type . More...
 
typedef std::function< bool(multi_link_registry< ISource< size_t > >::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...
 
- Protected Attributes inherited from Concurrency::propagator_block< single_link_registry< ITarget< _Destination_type > >, multi_link_registry< ISource< size_t > > >
_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< _Destination_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< _Destination_type > > _M_connectedTargets
 Connected targets More...
 
_MessageProcessorType _M_messageProcessor
 Processor used for asynchronous message handling More...
 

Detailed Description

template<typename _Type, typename _Destination_type, join_type _Jtype>
class Concurrency::_Join_node< _Type, _Destination_type, _Jtype >

Defines a block allowing sources of distinct types to be joined. Join node is a single-target, multi-source ordered propagator block

Template Parameters
_TypeThe payload tuple type
_JtypeThe kind of join this is, either 'greedy' or 'non-greedy'

Member Typedef Documentation

template<typename _Type, typename _Destination_type, join_type _Jtype>
typedef multi_link_registry<ISource<size_t> > Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_SourceLinkRegistry
private
template<typename _Type, typename _Destination_type, join_type _Jtype>
typedef single_link_registry<ITarget<_Destination_type> > Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_TargetLinkRegistry
private

Constructor & Destructor Documentation

template<typename _Type, typename _Destination_type, join_type _Jtype>
Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_Join_node ( )
inline

Constructs a join within the default scheduler, and places it on any schedule group of the scheduler's choosing.

12022  : _M_counter(std::tuple_size<_Destination_type>::value)
12023  {
12025  }
volatile long _M_counter
Definition: agents.h:12546
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<typename _Type, typename _Destination_type, join_type _Jtype>
Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_Join_node ( Scheduler &  _PScheduler)
inline

Constructs a join within the specified scheduler, and places it on any schedule group of the scheduler's choosing.

Parameters
_PSchedulerA reference to a scheduler instance.
12035  : _M_counter(std::tuple_size<_Destination_type>::value)
12036  {
12037  this->initialize_source_and_target(&_PScheduler);
12038  }
volatile long _M_counter
Definition: agents.h:12546
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<typename _Type, typename _Destination_type, join_type _Jtype>
Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_Join_node ( ScheduleGroup &  _PScheduleGroup)
inline

Constructs a join within the specified schedule group. The scheduler is implied by the schedule group.

Parameters
_PScheduleGroupA reference to a schedule group.
12048  : _M_counter(std::tuple_size<_Destination_type>::value)
12049  {
12050  this->initialize_source_and_target(NULL, &_PScheduleGroup);
12051  }
#define NULL
Definition: vcruntime.h:236
volatile long _M_counter
Definition: agents.h:12546
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<typename _Type, typename _Destination_type, join_type _Jtype>
Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::~_Join_node ( )
inline

Cleans up any resources that may have been created by the join.

12058  {
12059  // Remove all links
12060  this->remove_network_links();
12061 
12062  // Clean up any messages left in this message block
12064  }
void _Delete_stored_messages()
Deletes all messages currently stored in this message block. Should be called by the destructor to en...
Definition: agents.h:12501
void remove_network_links()
Removes all the source and target network links from this propagator_block object.
Definition: agents.h:5865
template<typename _Type, typename _Destination_type, join_type _Jtype>
Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_Join_node ( const _Join_node< _Type, _Destination_type, _Jtype > &  _Join)
private

Member Function Documentation

template<typename _Type, typename _Destination_type, join_type _Jtype>
message<_Destination_type>* Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_Create_send_message ( )
inlineprivate

Called when all the source messaging blocks have received their messages. The payloads are copied into local tuple and then packaged into a message to be propagated: _M_pSendMessage.

12450  {
12451  _Destination_type _Destination_tuple;
12452 
12453  // Populate the sources buffer
12454  ISource<size_t> * _Sources[std::tuple_size<_Type>::value];
12455  size_t _Index = 0;
12456 
12457  // Get an iterator which will keep a reference on the connected sources
12458  source_iterator _Iter = this->_M_connectedSources.begin();
12459 
12460  while (*_Iter != NULL)
12461  {
12462  ISource<size_t> * _PSource = *_Iter;
12463 
12464  if (_PSource == NULL)
12465  {
12466  // One of the sources disconnected
12467  break;
12468  }
12469 
12470  // Avoid buffer overrun
12471  if (_Index >= std::tuple_size<_Type>::value)
12472  {
12473  // More sources that we expect
12474  break;
12475  }
12476 
12477  _Sources[_Index] = *_Iter;
12478  _Index++;
12479  ++_Iter;
12480  }
12481 
12482  // The order nodes should not have unlinked while the join node is
12483  // active.
12484  if (_Index != std::tuple_size<_Type>::value)
12485  {
12486  // On debug build assert to help debugging
12487  _CONCRT_ASSERT(_Index == std::tuple_size<_Type>::value);
12488  return NULL;
12489  }
12490 
12491  _Populate_destination_tuple<0>(_Destination_tuple, _Sources);
12492 
12493  return new message<_Destination_type>(_Destination_tuple);
12494  }
#define NULL
Definition: vcruntime.h:236
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:5883
_SourceLinkManager::iterator source_iterator
The type of the iterator for the source_link_manager for this propagator_block.
Definition: agents.h:5596
template<typename _Type, typename _Destination_type, join_type _Jtype>
void Concurrency::_Join_node< _Type, _Destination_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.

12502  {
12503  // Delete any messages remaining in the output queue
12504  for (;;)
12505  {
12506  message<_Destination_type> * _Msg = _M_messageBuffer._Dequeue();
12507  if (_Msg == NULL)
12508  {
12509  break;
12510  }
12511  delete _Msg;
12512  }
12513  }
#define NULL
Definition: vcruntime.h:236
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:12549
template<typename _Type, typename _Destination_type, join_type _Jtype>
bool Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_Non_greedy_acquire_messages ( )
inlineprivate

Tries to acquire all of the messages from the _Non_greedy_nodes. Each node has already indicated that it has received a message that it can try to reserve. This function starts the reservation and consume process.

Returns
A bool indicating whether the reserve/consume of all messages succeeded.
12343  {
12344  _Destination_type _Destination_tuple;
12345 
12346  // Populate the sources buffer
12347  ISource<size_t> * _Sources[std::tuple_size<_Type>::value];
12348  size_t _Index = 0;
12349 
12350  // Get an iterator which will keep a reference on the connected sources
12351  source_iterator _Iter = this->_M_connectedSources.begin();
12352 
12353  while (*_Iter != NULL)
12354  {
12355  ISource<size_t> * _PSource = *_Iter;
12356 
12357  if (_PSource == NULL)
12358  {
12359  // One of the sources disconnected
12360  break;
12361  }
12362 
12363  if (_Index >= std::tuple_size<_Type>::value)
12364  {
12365  // More sources that we expect
12366  break;
12367  }
12368 
12369  _Sources[_Index] = _PSource;
12370  _Index++;
12371  ++_Iter;
12372  }
12373 
12374  // The order nodes should not have unlinked while the join node is
12375  // active.
12376 
12377  if (_Index != std::tuple_size<_Type>::value)
12378  {
12379  // On debug build assert to help debugging
12380  _CONCRT_ASSERT(_Index == std::tuple_size<_Type>::value);
12381  return false;
12382  }
12383 
12384  bool _IsAcquireSuccessful = _Try_consume_source_messages<0>(_Destination_tuple, _Sources);
12385 
12386  return _IsAcquireSuccessful;
12387  }
#define NULL
Definition: vcruntime.h:236
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:5883
_SourceLinkManager::iterator source_iterator
The type of the iterator for the source_link_manager for this propagator_block.
Definition: agents.h:5596
template<typename _Type, typename _Destination_type, join_type _Jtype>
template<int _Index>
void Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_Populate_destination_tuple ( _Destination_type &  _Destination_tuple,
ISource< size_t > **  _Sources 
)
inlineprivate

Copies payloads from all sources to destination tuple.

12521  {
12522  typedef _Order_node_base<typename std::remove_pointer_t<std::tuple_element_t<_Index, _Type>>::source_type> _Order_node_base_source_type;
12523  _Order_node_base_source_type * _Node = static_cast<_Order_node_base_source_type *>(_Sources[_Index]);
12524 
12525  std::get<_Index>(_Destination_tuple) = _Node->value();
12526  _Node->_Reset();
12527 
12528  _Populate_destination_tuple<_Index + 1>(_Destination_tuple, _Sources);
12529  }
single_link_registry< ITarget< _Destination_type > >::type::type source_type
A type alias for _Type .
Definition: agents.h:2737
template<typename _Type, typename _Destination_type, join_type _Jtype>
template<>
void Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_Populate_destination_tuple ( _Destination_type &  ,
ISource< size_t > **   
)
inlineprivate

Provides a sentinel template specialization for _Populate_destination_tuple recursive template expansion.

12537  {
12538  }
template<typename _Type, typename _Destination_type, join_type _Jtype>
void Concurrency::_Join_node< _Type, _Destination_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
12397  {
12398  message<_Target_type> * _Msg = _MessageBuffer._Peek();
12399 
12400  // If someone has reserved the _Head message, don't propagate anymore
12401  if (this->_M_pReservedFor != NULL)
12402  {
12403  return;
12404  }
12405 
12406  while (_Msg != NULL)
12407  {
12408  message_status _Status = declined;
12409 
12410  // Always start from the first target that linked
12411  for (target_iterator _Iter = this->_M_connectedTargets.begin(); *_Iter != NULL; ++_Iter)
12412  {
12413  ITarget<_Target_type> * _PTarget = *_Iter;
12414  _Status = _PTarget->propagate(_Msg, this);
12415 
12416  // Ownership of message changed. Do not propagate this
12417  // message to any other target.
12418  if (_Status == accepted)
12419  {
12420  break;
12421  }
12422 
12423  // If the target just propagated to reserved this message, stop
12424  // propagating it to others
12425  if (this->_M_pReservedFor != NULL)
12426  {
12427  break;
12428  }
12429  }
12430 
12431  // If status is anything other than accepted, then the head message
12432  // was not propagated out. Thus, nothing after it in the queue can
12433  // be propagated out. Cease propagation.
12434  if (_Status != accepted)
12435  {
12436  break;
12437  }
12438 
12439  // Get the next message
12440  _Msg = _MessageBuffer._Peek();
12441  }
12442  }
_Message * _Peek()
Definition: agents.h:227
single_link_registry< ITarget< _Destination_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< _Destination_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<typename _Type, typename _Destination_type, join_type _Jtype>
template<int _Index>
bool Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_Try_consume_source_messages ( _Destination_type &  _Destination_tuple,
ISource< size_t > **  _Sources 
)
inlineprivate

Tries to reserve from all sources. If successful, it will consume all the messages

Returns
A bool indicating whether the consumption attempt worked.
Template Parameters
_IndexThe highest-number index of the join's sources
12286  {
12287  typedef _Non_greedy_node<typename std::remove_pointer_t<std::tuple_element_t<_Index, _Type>>::source_type> _Non_greedy_node_source_type;
12288  _Non_greedy_node_source_type * _Node = static_cast<_Non_greedy_node_source_type *>(_Sources[_Index]);
12289 
12290  // Increment the counter once for each reservation
12292 
12293  if (_Node->_Reserve_received_message())
12294  {
12295  bool _Ret_val = _Try_consume_source_messages<_Index + 1>(_Destination_tuple, _Sources);
12296 
12297  if (_Ret_val)
12298  {
12299  _Node->_Consume_received_message();
12300  }
12301  else
12302  {
12303  if (_Node->_Release_received_message())
12304  {
12305  // If _Release_received_message() restored the ID, decrement the count for that
12306  // restoration
12307  if (_InterlockedDecrement(&_M_counter) == 0)
12308  {
12309  this->async_send(NULL);
12310  }
12311  }
12312  }
12313 
12314  return _Ret_val;
12315  }
12316 
12317  return false;
12318  }
#define NULL
Definition: vcruntime.h:236
single_link_registry< ITarget< _Destination_type > >::type::type source_type
A type alias for _Type .
Definition: agents.h:2737
volatile long _M_counter
Definition: agents.h:12546
long __cdecl _InterlockedDecrement(long volatile *)
long __cdecl _InterlockedIncrement(long volatile *)
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<typename _Type, typename _Destination_type, join_type _Jtype>
template<>
bool Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_Try_consume_source_messages ( _Destination_type &  ,
ISource< size_t > **   
)
inlineprivate

Provides a sentinel template specialization for _Try_consume_source_messages recursive template expansion.

Returns
A bool indicating whether the consumption attempt worked.
12329  {
12330  return true;
12331  }
template<typename _Type, typename _Destination_type, join_type _Jtype>
virtual message<_Destination_type>* Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::accept_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Accepts an offered message by the source, transferring ownership to the caller.

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

Implements Concurrency::source_block< single_link_registry< ITarget< _Destination_type > >, _MessageProcessorType >.

12124  {
12125  //
12126  // Peek at the head message in the message buffer. If the IDs match
12127  // dequeue and transfer ownership
12128  //
12129  message<_Destination_type> * _Msg = NULL;
12130 
12131  if (_M_messageBuffer._Is_head(_MsgId))
12132  {
12133  _Msg = _M_messageBuffer._Dequeue();
12134  }
12135 
12136  return _Msg;
12137  }
#define NULL
Definition: vcruntime.h:236
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:12549
template<typename _Type, typename _Destination_type, join_type _Jtype>
virtual message<_Destination_type>* Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::consume_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

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

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

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

Implements Concurrency::source_block< single_link_registry< ITarget< _Destination_type > >, _MessageProcessorType >.

12174  {
12175  // By default, accept the message
12176  return accept_message(_MsgId);
12177  }
virtual message< _Destination_type > * accept_message(runtime_object_identity _MsgId)
Accepts an offered message by the source, transferring ownership to the caller.
Definition: agents.h:12123
template<typename _Type, typename _Destination_type, join_type _Jtype>
virtual void Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::link_target_notification ( _Inout_ ITarget< _Destination_type > *  )
inlineprotectedvirtual

Notification that a target was linked to this source.

Parameters
_PTargetA pointer to the newly linked target.
12216  {
12217  // There is only a single target.
12219  }
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:12549
void _Propagate_priority_order(::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
Propagate messages in priority order
Definition: agents.h:12396
template<typename _Type, typename _Destination_type, join_type _Jtype>
_Join_node const& Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::operator= ( _Join_node< _Type, _Destination_type, _Jtype > const &  )
private
template<typename _Type, typename _Destination_type, join_type _Jtype>
virtual message_status Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::propagate_message ( message< size_t > *  _PMessage,
ISource< size_t > *  _PSource 
)
inlineprotectedvirtual

Asynchronously passes a message from an ISource block to this ITarget 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.
12084  {
12085  // This join block is connected to the _Order_node sources, which know not to send
12086  // any more messages until join propagates them further. That is why join can
12087  // always accept the incoming messages.
12088 
12089  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
12090 
12091  //
12092  // Source block created an int message only to notify join that the real
12093  // payload is available. There is no need to keep this message around.
12094  //
12095  _CONCRT_ASSERT(_PMessage != NULL);
12096  delete _PMessage;
12097 
12098  long _Ret_val = _InterlockedDecrement(&_M_counter);
12099 
12100  _CONCRT_ASSERT(_Ret_val >= 0);
12101 
12102  if (_Ret_val == 0)
12103  {
12104  //
12105  // All source messages are now received so join can propagate them further
12106  //
12107  this->async_send(NULL);
12108  }
12109 
12110  return accepted;
12111  }
#define NULL
Definition: vcruntime.h:236
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
volatile long _M_counter
Definition: agents.h:12546
virtual message< _Type > * accept(runtime_object_identity _MsgId, _Inout_ ITarget< _Type > *_PTarget)=0
When overridden in a derived class, accepts a message that was offered by this ISource block...
runtime_object_identity msg_id() const
Returns the ID of the message object.
Definition: agents.h:1861
The target accepted the message.
Definition: agents.h:1746
long __cdecl _InterlockedDecrement(long volatile *)
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<typename _Type, typename _Destination_type, join_type _Jtype>
virtual void Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::propagate_to_any_targets ( _Inout_opt_ message< _Destination_type > *  )
inlineprotectedvirtual

Takes the message and propagates it to all the targets of this join block.

Parameters
_PMessageA pointer to a new message.

This function packages source payloads into a tuple message and immediately sends it to the targets.

12232  {
12233  message<_Destination_type> * _Msg = NULL;
12234 
12235  if (_M_counter == 0)
12236  {
12237  bool fIsNonGreedy = (_Jtype == non_greedy);
12238 
12239  if (fIsNonGreedy)
12240  {
12242  {
12243  return;
12244  }
12245  }
12246 
12247  if (!fIsNonGreedy)
12248  {
12249  // Because a greedy join has captured all input, we can reset
12250  // the counter to the total number of inputs
12251  _InterlockedExchange(&_M_counter, std::tuple_size<_Destination_type>::value);
12252  }
12253 
12254  _Msg = _Create_send_message();
12255  }
12256 
12257  if (_Msg != NULL)
12258  {
12259  _M_messageBuffer._Enqueue(_Msg);
12260 
12261  if (!_M_messageBuffer._Is_head(_Msg->msg_id()))
12262  {
12263  // another message is at the head of the outbound message queue and blocked
12264  // simply return
12265  return;
12266  }
12267  }
12268 
12270  }
#define NULL
Definition: vcruntime.h:236
bool _Non_greedy_acquire_messages()
Tries to acquire all of the messages from the _Non_greedy_nodes. Each node has already indicated that...
Definition: agents.h:12342
Non-greedy join messaging blocks postpone messages and try and consume them after all have arrived...
Definition: agents.h:9130
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:12549
volatile long _M_counter
Definition: agents.h:12546
message< _Destination_type > * _Create_send_message()
Called when all the source messaging blocks have received their messages. The payloads are copied int...
Definition: agents.h:12449
void _Propagate_priority_order(::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
Propagate messages in priority order
Definition: agents.h:12396
template<typename _Type, typename _Destination_type, join_type _Jtype>
virtual void Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::release_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Releases a previous message reservation.

Parameters
_MsgIdThe runtime object identity of the message.

Implements Concurrency::source_block< single_link_registry< ITarget< _Destination_type > >, _MessageProcessorType >.

12187  {
12188  // The head message is the one reserved.
12189  if (!_M_messageBuffer._Is_head(_MsgId))
12190  {
12191  throw message_not_found();
12192  }
12193  }
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:12549
template<typename _Type, typename _Destination_type, join_type _Jtype>
virtual bool Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::reserve_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Reserves a message previously offered by the source.

Parameters
_MsgIdThe runtime object identity of the message.
Returns
A bool indicating whether the reservation worked or not.

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< _Destination_type > >, _MessageProcessorType >.

12154  {
12155  // Allow reservation if this is the head message
12156  return _M_messageBuffer._Is_head(_MsgId);
12157  }
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:12549
template<typename _Type, typename _Destination_type, join_type _Jtype>
virtual void Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::resume_propagation ( )
inlineprotectedvirtual

Resumes propagation after a reservation has been released

Implements Concurrency::source_block< single_link_registry< ITarget< _Destination_type > >, _MessageProcessorType >.

12200  {
12201  // If there are any messages in the buffer, propagate them out
12202  if (_M_messageBuffer._Count() > 0)
12203  {
12204  this->async_send(NULL);
12205  }
12206  }
#define NULL
Definition: vcruntime.h:236
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:12549
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<typename _Type, typename _Destination_type, join_type _Jtype>
volatile long Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_M_counter
private
template<typename _Type, typename _Destination_type, join_type _Jtype>
::Concurrency::details::_Queue<message<_Destination_type> > Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_M_messageBuffer
private
template<typename _Type, typename _Destination_type, join_type _Jtype>
_Type Concurrency::_Join_node< _Type, _Destination_type, _Jtype >::_M_sourceTuple
private

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