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

A multitype_join messaging block is a multi-source, single-target messaging block that combines together messages of different types from each of its sources and offers a tuple of the combined messages to its targets. More...

#include <agents.h>

Inheritance diagram for Concurrency::multitype_join< _Type, _Jtype >:
Concurrency::ISource< _Unwrap< _Type >::type >

Public Types

typedef _Unwrap< _Type >::type _Destination_type
 
typedef _Type type
 A type alias for _Type . More...
 
- Public Types inherited from Concurrency::ISource< _Unwrap< _Type >::type >
typedef _Unwrap< _Type >::type source_type
 A type alias for _Type . More...
 

Public Member Functions

 multitype_join (_Type _Tuple)
 Constructs a multitype_join messaging block. More...
 
 multitype_join (multitype_join &&_Join)
 Constructs a multitype_join messaging block. More...
 
 ~multitype_join ()
 Destroys the multitype_join messaging block. More...
 
virtual void link_target (_Inout_ ITarget< _Destination_type > *_PTarget)
 Links a target block to this multitype_join messaging block. More...
 
virtual void unlink_target (_Inout_ ITarget< _Destination_type > *_PTarget)
 Unlinks a target block from this multitype_join messaging block. More...
 
virtual void unlink_targets ()
 Unlinks all targets from this multitype_join messaging block. More...
 
virtual message< _Destination_type > * accept (runtime_object_identity _MsgId, _Inout_ ITarget< _Destination_type > *_PTarget)
 Accepts a message that was offered by this multitype_join block, transferring ownership to the caller. More...
 
virtual bool reserve (runtime_object_identity _MsgId, _Inout_ ITarget< _Destination_type > *_PTarget)
 Reserves a message previously offered by this multitype_join messaging block. More...
 
virtual message< _Destination_type > * consume (runtime_object_identity _MsgId, _Inout_ ITarget< _Destination_type > *_PTarget)
 Consumes a message previously offered by the multitype_join messaging block and successfully reserved by the target, transferring ownership to the caller. More...
 
virtual void release (runtime_object_identity _MsgId, _Inout_ ITarget< _Destination_type > *_PTarget)
 Releases a previous successful message reservation. More...
 
virtual void acquire_ref (_Inout_ ITarget< _Destination_type > *_PTarget)
 Acquires a reference count on this multitype_join messaging block, to prevent deletion. More...
 
virtual void release_ref (_Inout_ ITarget< _Destination_type > *_PTarget)
 Releases a reference count on this multiple_join messaging block. More...
 
- Public Member Functions inherited from Concurrency::ISource< _Unwrap< _Type >::type >
virtual ~ISource ()
 Destroys the ISource object. More...
 
virtual void link_target (_Inout_ ITarget< _Unwrap< _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< _Unwrap< _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< _Unwrap< _Type >::type > * accept (runtime_object_identity _MsgId, _Inout_ ITarget< _Unwrap< _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< _Unwrap< _Type >::type > *_PTarget)=0
 When overridden in a derived class, reserves a message previously offered by this ISource block. More...
 
virtual message< _Unwrap< _Type >::type > * consume (runtime_object_identity _MsgId, _Inout_ ITarget< _Unwrap< _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< _Unwrap< _Type >::type > *_PTarget)=0
 When overridden in a derived class, releases a previous successful message reservation. More...
 
virtual void acquire_ref (_Inout_ ITarget< _Unwrap< _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< _Unwrap< _Type >::type > *_PTarget)=0
 When overridden in a derived class, releases a reference count on this ISource block. More...
 

Private Member Functions

template<int _Index>
void _Initialize_joins ()
 Constructs and initializes a _Order_node for each tuple messaging block passed in. More...
 
template<>
void _Initialize_joins ()
 Provides a sentinel template specialization for _Initialize_joins recursive template expansion. More...
 
template<int _Index>
void _Delete_joins ()
 Deletes all _Order_node elements that were created in _Initialize_joins. More...
 
template<>
void _Delete_joins ()
 Provides a sentinel template specialization for _Delete_joins recursive template expansion. More...
 
multitype_join const & operator= (multitype_join const &)
 
 multitype_join (multitype_join const &)
 

Private Attributes

void_M_pSourceJoins [std::tr1::tuple_size< _Type >::value]
 
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
 
_Type _M_sourceTuple
 
Scheduler * _M_pScheduler
 
ScheduleGroup * _M_pScheduleGroup
 

Additional Inherited Members

- Protected Member Functions inherited from Concurrency::ISource< _Unwrap< _Type >::type >
void _Invoke_link_source (ITarget< _Unwrap< _Type >::type > *_PLinkFrom)
 Links this source to a target. More...
 
void _Invoke_unlink_source (ITarget< _Unwrap< _Type >::type > *_PUnlinkFrom)
 Unlinks this source from a target. More...
 

Detailed Description

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

A multitype_join messaging block is a multi-source, single-target messaging block that combines together messages of different types from each of its sources and offers a tuple of the combined messages to its targets.

Template Parameters
_TypeThe tuple 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, join Class, join_type Enumeration, make_join Function, make_greedy_join Function, tuple Class

Member Typedef Documentation

template<typename _Type , join_type _Jtype = non_greedy>
typedef _Unwrap<_Type>::type Concurrency::multitype_join< _Type, _Jtype >::_Destination_type
template<typename _Type , join_type _Jtype = non_greedy>
typedef _Type Concurrency::multitype_join< _Type, _Jtype >::type

A type alias for _Type .

Constructor & Destructor Documentation

template<typename _Type , join_type _Jtype = non_greedy>
Concurrency::multitype_join< _Type, _Jtype >::multitype_join ( _Type  _Tuple)
inlineexplicit

Constructs a multitype_join messaging block.

Parameters
_TupleA tuple of sources for this multitype_join messaging block.

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

Move construction is not performed under a lock, which means that it is up to the user to make sure that there are no light-weight tasks in flight at the time of moving. Otherwise, numerous races can occur, leading to exceptions or inconsistent state.

See also
Scheduler Class, ScheduleGroup Class
10878  {
10879  _M_pJoinNode = new _Join_node<_Type, _Destination_type, _Jtype>();
10880  _Initialize_joins<0>();
10881  }
Scheduler * _M_pScheduler
Definition: agents.h:11244
#define NULL
Definition: crtdbg.h:30
_Type _M_sourceTuple
Definition: agents.h:11241
ScheduleGroup * _M_pScheduleGroup
Definition: agents.h:11247
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
Concurrency::multitype_join< _Type, _Jtype >::multitype_join ( multitype_join< _Type, _Jtype > &&  _Join)
inline

Constructs a multitype_join messaging block.

Parameters
_JoinA multitype_join messaging block to copy from. Note that the original object is orphaned, making this a move constructor.

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

Move construction is not performed under a lock, which means that it is up to the user to make sure that there are no light-weight tasks in flight at the time of moving. Otherwise, numerous races can occur, leading to exceptions or inconsistent state.

See also
Scheduler Class, ScheduleGroup Class
10966  {
10967  // Copy scheduler group or scheduler to the new object.
10968  _M_pScheduleGroup = _Join._M_pScheduleGroup;
10969  _M_pScheduler = _Join._M_pScheduler;
10970 
10971  // Single assignment is heap allocated, so simply copy the pointer. If it already has
10972  // a value, it will be preserved.
10973  _M_pJoinNode = _Join._M_pJoinNode;
10974  _Join._M_pJoinNode = NULL;
10975 
10976  // Invoke copy assignment for tuple to copy pointers to message blocks.
10977  _M_sourceTuple = _Join._M_sourceTuple;
10978 
10979  // Copy the pointers to order nodes to a new object and zero out in the old object.
10980  memcpy(_M_pSourceJoins, _Join._M_pSourceJoins, sizeof(_M_pSourceJoins));
10981  memset(_Join._M_pSourceJoins, 0, sizeof(_M_pSourceJoins));
10982  }
Scheduler * _M_pScheduler
Definition: agents.h:11244
#define NULL
Definition: crtdbg.h:30
_Type _M_sourceTuple
Definition: agents.h:11241
void * _M_pSourceJoins[std::tr1::tuple_size< _Type >::value]
Definition: agents.h:11235
ScheduleGroup * _M_pScheduleGroup
Definition: agents.h:11247
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
Concurrency::multitype_join< _Type, _Jtype >::~multitype_join ( )
inline

Destroys the multitype_join messaging block.

10989  {
10990  delete _M_pJoinNode;
10991  _Delete_joins<0>();
10992  }
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
Concurrency::multitype_join< _Type, _Jtype >::multitype_join ( multitype_join< _Type, _Jtype > const &  )
private

Member Function Documentation

template<typename _Type , join_type _Jtype = non_greedy>
template<int _Index>
void Concurrency::multitype_join< _Type, _Jtype >::_Delete_joins ( )
inlineprivate

Deletes all _Order_node elements that were created in _Initialize_joins.

Template Parameters
_IndexThe highest-number index of the multitype_join's sources
11219  {
11220  delete reinterpret_cast<_Order_node_base<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> *>(_M_pSourceJoins[_Index]);
11221  _M_pSourceJoins[_Index] = NULL;
11222  _Delete_joins<_Index + 1>();
11223  }
#define NULL
Definition: crtdbg.h:30
void * _M_pSourceJoins[std::tr1::tuple_size< _Type >::value]
Definition: agents.h:11235
template<typename _Type , join_type _Jtype = non_greedy>
template<>
void Concurrency::multitype_join< _Type, _Jtype >::_Delete_joins ( )
inlineprivate

Provides a sentinel template specialization for _Delete_joins recursive template expansion.

11231  {
11232  }
template<typename _Type , join_type _Jtype = non_greedy>
template<int _Index>
void Concurrency::multitype_join< _Type, _Jtype >::_Initialize_joins ( )
inlineprivate

Constructs and initializes a _Order_node for each tuple messaging block passed in.

Template Parameters
_IndexThe highest-number index of the multitype_join's sources
11160  {
11161  std::tr1::tuple_element<_Index, _Type>::type _Item = std::tr1::get<_Index>(_M_sourceTuple);
11162  _Order_node_base<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> * _Order_node_element = NULL;
11163 
11164  bool fIsNonGreedy = (_Jtype == non_greedy);
11165 
11166  if (fIsNonGreedy)
11167  {
11168  if (_M_pScheduleGroup != NULL)
11169  {
11170  _Order_node_element = new _Non_greedy_node<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> (*_M_pScheduleGroup, _Item, _Index);
11171  }
11172  else if (_M_pScheduler != NULL)
11173  {
11174  _Order_node_element = new _Non_greedy_node<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> (*_M_pScheduler, _Item, _Index);
11175  }
11176  else
11177  {
11178  _Order_node_element = new _Non_greedy_node<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> (_Item, _Index);
11179  }
11180  }
11181  else
11182  {
11183  if (_M_pScheduleGroup != NULL)
11184  {
11185  _Order_node_element = new _Greedy_node<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> (*_M_pScheduleGroup, _Item, _Index);
11186  }
11187  else if (_M_pScheduler != NULL)
11188  {
11189  _Order_node_element = new _Greedy_node<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> (*_M_pScheduler, _Item, _Index);
11190  }
11191  else
11192  {
11193  _Order_node_element = new _Greedy_node<std::tr1::remove_pointer<std::tr1::tuple_element<_Index, _Type>::type>::type::source_type> (_Item, _Index);
11194  }
11195  }
11196  _M_pSourceJoins[_Index] = _Order_node_element;
11197  _Order_node_element->link_target(_M_pJoinNode);
11198  _Initialize_joins<_Index + 1>();
11199  }
Non-greedy join messaging blocks postpone messages and try and consume them after all have arrived...
Definition: agents.h:7439
Scheduler * _M_pScheduler
Definition: agents.h:11244
#define NULL
Definition: crtdbg.h:30
_Type _M_sourceTuple
Definition: agents.h:11241
void * _M_pSourceJoins[std::tr1::tuple_size< _Type >::value]
Definition: agents.h:11235
ScheduleGroup * _M_pScheduleGroup
Definition: agents.h:11247
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
template<>
void Concurrency::multitype_join< _Type, _Jtype >::_Initialize_joins ( )
inlineprivate

Provides a sentinel template specialization for _Initialize_joins recursive template expansion.

11207  {
11208  }
template<typename _Type , join_type _Jtype = non_greedy>
virtual message<_Destination_type>* Concurrency::multitype_join< _Type, _Jtype >::accept ( runtime_object_identity  _MsgId,
_Inout_ ITarget< _Destination_type > *  _PTarget 
)
inlinevirtual

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

Parameters
_MsgIdThe runtime_object_identity of the offered message object.
_PTargetA pointer to the target block that is calling the accept method.
Returns
A pointer to the message that the caller now has ownership of.
11051  {
11052  return _M_pJoinNode->accept(_MsgId, _PTarget);
11053  }
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
virtual void Concurrency::multitype_join< _Type, _Jtype >::acquire_ref ( _Inout_ ITarget< _Destination_type > *  _PTarget)
inlinevirtual

Acquires a reference count on this multitype_join messaging block, to prevent deletion.

Parameters
_PTargetA pointer to the target block that is calling this method.

This method is called by an ITarget object that is being linked to this source during the link_target method.

11129  {
11130  _M_pJoinNode->acquire_ref(_PTarget);
11131  }
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
virtual message<_Destination_type>* Concurrency::multitype_join< _Type, _Jtype >::consume ( runtime_object_identity  _MsgId,
_Inout_ ITarget< _Destination_type > *  _PTarget 
)
inlinevirtual

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

Parameters
_MsgIdThe runtime_object_identity of the reserved message object.
_PTargetA pointer to the target block that is calling the consume method.
Returns
A pointer to the message object that the caller now has ownership of.

The consume method is similar to accept, but must always be preceded by a call to reserve that returned true.

11098  {
11099  return _M_pJoinNode->consume(_MsgId, _PTarget);
11100  }
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
virtual void Concurrency::multitype_join< _Type, _Jtype >::link_target ( _Inout_ ITarget< _Destination_type > *  _PTarget)
inlinevirtual

Links a target block to this multitype_join messaging block.

Parameters
_PTargetA pointer to an ITarget block to link to this multitype_join messaging block.
11012  {
11013  _M_pJoinNode->link_target(_PTarget);
11014  }
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
multitype_join const& Concurrency::multitype_join< _Type, _Jtype >::operator= ( multitype_join< _Type, _Jtype > const &  )
private
template<typename _Type , join_type _Jtype = non_greedy>
virtual void Concurrency::multitype_join< _Type, _Jtype >::release ( runtime_object_identity  _MsgId,
_Inout_ ITarget< _Destination_type > *  _PTarget 
)
inlinevirtual

Releases a previous successful message reservation.

Parameters
_MsgIdThe runtime_object_identity of the message object being released.
_PTargetA pointer to the target block that is calling the release method.
11113  {
11114  _M_pJoinNode->release(_MsgId, _PTarget);
11115  }
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
virtual void Concurrency::multitype_join< _Type, _Jtype >::release_ref ( _Inout_ ITarget< _Destination_type > *  _PTarget)
inlinevirtual

Releases a reference count on this multiple_join messaging block.

Parameters
_PTargetA pointer to the target block that is calling this method.

This method is called by an ITarget object that is being unlinked from this source. The source block is allowed to release any resources reserved for the target block.

11145  {
11146  _M_pJoinNode->release_ref(_PTarget);
11147  }
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
virtual bool Concurrency::multitype_join< _Type, _Jtype >::reserve ( runtime_object_identity  _MsgId,
_Inout_ ITarget< _Destination_type > *  _PTarget 
)
inlinevirtual

Reserves a message previously offered by this multitype_join messaging block.

Parameters
_MsgIdThe runtime_object_identity of the message object being reserved.
_PTargetA pointer to the target block that is calling the reserve method.
Returns
true if the message was successfully reserved, false otherwise. Reservations can fail for many reasons, including: the message was already reserved or accepted by another target, the source could deny reservations, and so forth.

After you call reserve, if it succeeds, you must call either consume or release in order to take or give up possession of the message, respectively.

11075  {
11076  return _M_pJoinNode->reserve(_MsgId, _PTarget);
11077  }
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
virtual void Concurrency::multitype_join< _Type, _Jtype >::unlink_target ( _Inout_ ITarget< _Destination_type > *  _PTarget)
inlinevirtual

Unlinks a target block from this multitype_join messaging block.

Parameters
_PTargetA pointer to an ITarget block to unlink from this multitype_join messaging block.
11024  {
11025  _M_pJoinNode->unlink_target(_PTarget);
11026  }
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238
template<typename _Type , join_type _Jtype = non_greedy>
virtual void Concurrency::multitype_join< _Type, _Jtype >::unlink_targets ( )
inlinevirtual

Unlinks all targets from this multitype_join messaging block.

Implements Concurrency::ISource< _Unwrap< _Type >::type >.

11033  {
11034  _M_pJoinNode->unlink_targets();
11035  }
_Join_node< _Type, _Destination_type, _Jtype > * _M_pJoinNode
Definition: agents.h:11238

Member Data Documentation

template<typename _Type , join_type _Jtype = non_greedy>
_Join_node<_Type, _Destination_type, _Jtype>* Concurrency::multitype_join< _Type, _Jtype >::_M_pJoinNode
private
template<typename _Type , join_type _Jtype = non_greedy>
ScheduleGroup* Concurrency::multitype_join< _Type, _Jtype >::_M_pScheduleGroup
private
template<typename _Type , join_type _Jtype = non_greedy>
Scheduler* Concurrency::multitype_join< _Type, _Jtype >::_M_pScheduler
private
template<typename _Type , join_type _Jtype = non_greedy>
void* Concurrency::multitype_join< _Type, _Jtype >::_M_pSourceJoins[std::tr1::tuple_size< _Type >::value]
private
template<typename _Type , join_type _Jtype = non_greedy>
_Type Concurrency::multitype_join< _Type, _Jtype >::_M_sourceTuple
private

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