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

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.

10292  : _M_counter(std::tr1::tuple_size<_Destination_type>::value)
10293  {
10295  }
volatile long _M_counter
Definition: agents.h:10816
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<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.
10305  : _M_counter(std::tr1::tuple_size<_Destination_type>::value)
10306  {
10307  initialize_source_and_target(&_PScheduler);
10308  }
volatile long _M_counter
Definition: agents.h:10816
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<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.
10318  : _M_counter(std::tr1::tuple_size<_Destination_type>::value)
10319  {
10320  initialize_source_and_target(NULL, &_PScheduleGroup);
10321  }
volatile long _M_counter
Definition: agents.h:10816
#define NULL
Definition: crtdbg.h:30
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<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.

10328  {
10329  // Remove all links
10331 
10332  // Clean up any messages left in this message block
10334  }
void _Delete_stored_messages()
Deletes all messages currently stored in this message block. Should be called by the destructor to en...
Definition: agents.h:10771
void remove_network_links()
Removes all the source and target network links from this propagator_block object.
Definition: agents.h:4212
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.

10720  {
10721  _Destination_type _Destination_tuple;
10722 
10723  // Populate the sources buffer
10724  ISource<size_t> * _Sources[std::tr1::tuple_size<_Type>::value];
10725  size_t _Index = 0;
10726 
10727  // Get an iterator which will keep a reference on the connected sources
10729 
10730  while (*_Iter != NULL)
10731  {
10732  ISource<size_t> * _PSource = *_Iter;
10733 
10734  if (_PSource == NULL)
10735  {
10736  // One of the sources disconnected
10737  break;
10738  }
10739 
10740  // Avoid buffer overrun
10741  if (_Index >= std::tr1::tuple_size<_Type>::value)
10742  {
10743  // More sources that we expect
10744  break;
10745  }
10746 
10747  _Sources[_Index] = *_Iter;
10748  _Index++;
10749  ++_Iter;
10750  }
10751 
10752  // The order nodes should not have unlinked while the join node is
10753  // active.
10754  if (_Index != std::tr1::tuple_size<_Type>::value)
10755  {
10756  // On debug build assert to help debugging
10757  _CONCRT_ASSERT(_Index == std::tr1::tuple_size<_Type>::value);
10758  return NULL;
10759  }
10760 
10761  _Populate_destination_tuple<0>(_Destination_tuple, _Sources);
10762 
10763  return new message<_Destination_type>(_Destination_tuple);
10764  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
#define NULL
Definition: crtdbg.h:30
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:4230
_SourceLinkManager::iterator source_iterator
The type of the iterator for the source_link_manager for this propagator_block.
Definition: agents.h:3946
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.

10772  {
10773  // Delete any messages remaining in the output queue
10774  for (;;)
10775  {
10776  message<_Destination_type> * _Msg = _M_messageBuffer._Dequeue();
10777  if (_Msg == NULL)
10778  {
10779  break;
10780  }
10781  delete _Msg;
10782  }
10783  }
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:10819
#define NULL
Definition: crtdbg.h:30
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.
10613  {
10614  _Destination_type _Destination_tuple;
10615 
10616  // Populate the sources buffer
10617  ISource<size_t> * _Sources[std::tr1::tuple_size<_Type>::value];
10618  size_t _Index = 0;
10619 
10620  // Get an iterator which will keep a reference on the connected sources
10622 
10623  while (*_Iter != NULL)
10624  {
10625  ISource<size_t> * _PSource = *_Iter;
10626 
10627  if (_PSource == NULL)
10628  {
10629  // One of the sources disconnected
10630  break;
10631  }
10632 
10633  if (_Index >= std::tr1::tuple_size<_Type>::value)
10634  {
10635  // More sources that we expect
10636  break;
10637  }
10638 
10639  _Sources[_Index] = _PSource;
10640  _Index++;
10641  ++_Iter;
10642  }
10643 
10644  // The order nodes should not have unlinked while the join node is
10645  // active.
10646 
10647  if (_Index != std::tr1::tuple_size<_Type>::value)
10648  {
10649  // On debug build assert to help debugging
10650  _CONCRT_ASSERT(_Index == std::tr1::tuple_size<_Type>::value);
10651  return false;
10652  }
10653 
10654  bool _IsAcquireSuccessful = _Try_consume_source_messages<0>(_Destination_tuple, _Sources);
10655 
10656  return _IsAcquireSuccessful;
10657  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
#define NULL
Definition: crtdbg.h:30
_SourceLinkManager _M_connectedSources
The container for all the sources connected to this block.
Definition: agents.h:4230
_SourceLinkManager::iterator source_iterator
The type of the iterator for the source_link_manager for this propagator_block.
Definition: agents.h:3946
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.

10791  {
10792  _Order_node_base<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> * _Node =
10793  static_cast<_Order_node_base<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> *>(_Sources[_Index]);
10794 
10795  std::tr1::get<_Index>(_Destination_tuple) = _Node->value();
10796  _Node->_Reset();
10797 
10798  _Populate_destination_tuple<_Index + 1>(_Destination_tuple, _Sources);
10799  }
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.

10807  {
10808  }
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
10667  {
10668  message<_Target_type> * _Msg = _MessageBuffer._Peek();
10669 
10670  // If someone has reserved the _Head message, don't propagate anymore
10671  if (_M_pReservedFor != NULL)
10672  {
10673  return;
10674  }
10675 
10676  while (_Msg != NULL)
10677  {
10678  message_status _Status = declined;
10679 
10680  // Always start from the first target that linked
10681  for (target_iterator _Iter = _M_connectedTargets.begin(); *_Iter != NULL; ++_Iter)
10682  {
10683  ITarget<_Target_type> * _PTarget = *_Iter;
10684  _Status = _PTarget->propagate(_Msg, this);
10685 
10686  // Ownership of message changed. Do not propagate this
10687  // message to any other target.
10688  if (_Status == accepted)
10689  {
10690  break;
10691  }
10692 
10693  // If the target just propagated to reserved this message, stop
10694  // propagating it to others
10695  if (_M_pReservedFor != NULL)
10696  {
10697  break;
10698  }
10699  }
10700 
10701  // If status is anything other than accepted, then the head message
10702  // was not propagated out. Thus, nothing after it in the queue can
10703  // be propagated out. Cease propagation.
10704  if (_Status != accepted)
10705  {
10706  break;
10707  }
10708 
10709  // Get the next message
10710  _Msg = _MessageBuffer._Peek();
10711  }
10712  }
_Message * _Peek()
Definition: agents.h:226
single_link_registry< ITarget< _Destination_type > >::iterator target_iterator
The iterator to walk the connected targets.
Definition: agents.h:3242
single_link_registry< ITarget< _Destination_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<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
10556  {
10557  _Non_greedy_node<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> * _Node =
10558  static_cast<_Non_greedy_node<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> *>(_Sources[_Index]);
10559 
10560  // Increment the counter once for each reservation
10562 
10563  if (_Node->_Reserve_received_message())
10564  {
10565  bool _Ret_val = _Try_consume_source_messages<_Index + 1>(_Destination_tuple, _Sources);
10566 
10567  if (_Ret_val)
10568  {
10569  _Node->_Consume_received_message();
10570  }
10571  else
10572  {
10573  if (_Node->_Release_received_message())
10574  {
10575  // If _Release_received_message() restored the ID, decrement the count for that
10576  // restoration
10577  if (_InterlockedDecrement(&_M_counter) == 0)
10578  {
10579  async_send(NULL);
10580  }
10581  }
10582  }
10583 
10584  return _Ret_val;
10585  }
10586 
10587  return false;
10588  }
volatile long _M_counter
Definition: agents.h:10816
#define NULL
Definition: crtdbg.h:30
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:3783
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.
10599  {
10600  return true;
10601  }
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 >.

10394  {
10395  //
10396  // Peek at the head message in the message buffer. If the IDs match
10397  // dequeue and transfer ownership
10398  //
10399  message<_Destination_type> * _Msg = NULL;
10400 
10401  if (_M_messageBuffer._Is_head(_MsgId))
10402  {
10403  _Msg = _M_messageBuffer._Dequeue();
10404  }
10405 
10406  return _Msg;
10407  }
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:10819
#define NULL
Definition: crtdbg.h:30
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 >.

10444  {
10445  // By default, accept the message
10446  return accept_message(_MsgId);
10447  }
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:10393
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.
10486  {
10487  // There is only a single target.
10489  }
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:10819
void _Propagate_priority_order(::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
Propagate messages in priority order
Definition: agents.h:10666
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.
10354  {
10355  // This join block is connected to the _Order_node sources, which know not to send
10356  // any more messages until join propagates them further. That is why join can
10357  // always accept the incoming messages.
10358 
10359  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
10360 
10361  //
10362  // Source block created an int message only to notify join that the real
10363  // payload is available. There is no need to keep this message around.
10364  //
10365  _CONCRT_ASSERT(_PMessage != NULL);
10366  delete _PMessage;
10367 
10368  long _Ret_val = _InterlockedDecrement(&_M_counter);
10369 
10370  _CONCRT_ASSERT(_Ret_val >= 0);
10371 
10372  if (_Ret_val == 0)
10373  {
10374  //
10375  // All source messages are now received so join can propagate them further
10376  //
10377  async_send(NULL);
10378  }
10379 
10380  return accepted;
10381  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
volatile long _M_counter
Definition: agents.h:10816
#define NULL
Definition: crtdbg.h:30
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:1860
The target accepted the message.
Definition: agents.h:1745
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:3783
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.

10502  {
10503  message<_Destination_type> * _Msg = NULL;
10504 
10505  if (_M_counter == 0)
10506  {
10507  bool fIsNonGreedy = (_Jtype == non_greedy);
10508 
10509  if (fIsNonGreedy)
10510  {
10512  {
10513  return;
10514  }
10515  }
10516 
10517  if (!fIsNonGreedy)
10518  {
10519  // Because a greedy join has captured all input, we can reset
10520  // the counter to the total number of inputs
10521  _InterlockedExchange(&_M_counter, std::tr1::tuple_size<_Destination_type>::value);
10522  }
10523 
10524  _Msg = _Create_send_message();
10525  }
10526 
10527  if (_Msg != NULL)
10528  {
10529  _M_messageBuffer._Enqueue(_Msg);
10530 
10531  if (!_M_messageBuffer._Is_head(_Msg->msg_id()))
10532  {
10533  // another message is at the head of the outbound message queue and blocked
10534  // simply return
10535  return;
10536  }
10537  }
10538 
10540  }
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:10612
Non-greedy join messaging blocks postpone messages and try and consume them after all have arrived...
Definition: agents.h:7439
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:10819
volatile long _M_counter
Definition: agents.h:10816
#define NULL
Definition: crtdbg.h:30
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:10719
void _Propagate_priority_order(::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
Propagate messages in priority order
Definition: agents.h:10666
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 >.

10457  {
10458  // The head message is the one reserved.
10459  if (!_M_messageBuffer._Is_head(_MsgId))
10460  {
10461  throw message_not_found();
10462  }
10463  }
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:10819
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 >.

10424  {
10425  // Allow reservation if this is the head message
10426  return _M_messageBuffer._Is_head(_MsgId);
10427  }
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:10819
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 >.

10470  {
10471  // If there are any messages in the buffer, propagate them out
10472  if (_M_messageBuffer._Count() > 0)
10473  {
10474  async_send(NULL);
10475  }
10476  }
::Concurrency::details::_Queue< message< _Destination_type > > _M_messageBuffer
Definition: agents.h:10819
#define NULL
Definition: crtdbg.h:30
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<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: