STLdoc
STLdocumentation
|
A choice
messaging block is a multi-source, single-target block that represents a control-flow interaction with a set of sources. The choice block will wait for any one of multiple sources to produce a message and will propagate the index of the source that produced the message.
More...
#include <agents.h>
Public Types | |
typedef _Type | type |
A type alias for _Type . More... | |
Public Types inherited from Concurrency::ISource< size_t > | |
typedef size_t | source_type |
A type alias for _Type . More... | |
Public Member Functions | |
choice (_Type _Tuple) | |
Constructs a choice messaging block. More... | |
choice (choice &&_Choice) | |
Constructs a choice messaging block. More... | |
~choice () | |
Destroys the choice messaging block. More... | |
bool | has_value () const |
Checks whether this choice messaging block has been initialized with a value yet. More... | |
size_t | index () |
Returns an index into the tuple representing the element selected by the choice messaging block. More... | |
template<typename _Payload_type > | |
_Payload_type const & | value () |
Gets the message whose index was selected by the choice messaging block. More... | |
virtual void | link_target (_Inout_ ITarget< size_t > *_PTarget) |
Links a target block to this choice messaging block. More... | |
virtual void | unlink_target (_Inout_ ITarget< size_t > *_PTarget) |
Unlinks a target block from this choice messaging block. More... | |
virtual void | unlink_targets () |
Unlinks all targets from this choice messaging block. More... | |
virtual message< size_t > * | accept (runtime_object_identity _MsgId, _Inout_ ITarget< size_t > *_PTarget) |
Accepts a message that was offered by this choice block, transferring ownership to the caller. More... | |
virtual bool | reserve (runtime_object_identity _MsgId, _Inout_ ITarget< size_t > *_PTarget) |
Reserves a message previously offered by this choice messaging block. More... | |
virtual message< size_t > * | consume (runtime_object_identity _MsgId, _Inout_ ITarget< size_t > *_PTarget) |
Consumes a message previously offered by this choice messaging block and successfully reserved by the target, transferring ownership to the caller. More... | |
virtual void | release (runtime_object_identity _MsgId, _Inout_ ITarget< size_t > *_PTarget) |
Releases a previous successful message reservation. More... | |
virtual void | acquire_ref (_Inout_ ITarget< size_t > *_PTarget) |
Acquires a reference count on this choice messaging block, to prevent deletion. More... | |
virtual void | release_ref (_Inout_ ITarget< size_t > *_PTarget) |
Releases a reference count on this choice messaging block. More... | |
Public Member Functions inherited from Concurrency::ISource< size_t > | |
virtual | ~ISource () |
Destroys the ISource object. More... | |
Private Types | |
template<int _Index> | |
using | _Reserving_node_source_type = _Reserving_node< typename std::remove_pointer_t< std::tuple_element_t< _Index, _Type >>::source_type > |
Private Member Functions | |
template<int _Index> | |
void | _Initialize_choices () |
Constructs and initializes a _Reserving_node for each tuple messaging block passed in. More... | |
template<> | |
void | _Initialize_choices () |
Provides a sentinel template specialization for _Initialize_choices recursive template expansion. More... | |
template<int _Index> | |
void | _Delete_choices () |
Deletes all _Reserving_node elements that were created in _Initialize_choices. More... | |
template<> | |
void | _Delete_choices () |
Provides a sentinel template specialization for _Delete_choices recursive template expansion. More... | |
choice const & | operator= (choice const &) |
choice (choice const &) | |
Private Attributes | |
void * | _M_pSourceChoices [std::tuple_size< _Type >::value] |
single_assignment< size_t > * | _M_pSingleAssignment |
_Type | _M_sourceTuple |
Scheduler * | _M_pScheduler |
ScheduleGroup * | _M_pScheduleGroup |
Additional Inherited Members | |
Protected Member Functions inherited from Concurrency::ISource< size_t > | |
void | _Invoke_link_source (ITarget< size_t > *_PLinkFrom) |
Links this source to a target. More... | |
void | _Invoke_unlink_source (ITarget< size_t > *_PUnlinkFrom) |
Unlinks this source from a target. More... | |
A choice
messaging block is a multi-source, single-target block that represents a control-flow interaction with a set of sources. The choice block will wait for any one of multiple sources to produce a message and will propagate the index of the source that produced the message.
_Type | A tuple -based type representing the payloads of the input sources. |
The choice block ensures that only one of the incoming messages is consumed.
For more information, see Asynchronous Message Blocks.
|
private |
typedef _Type Concurrency::choice< _Type >::type |
A type alias for _Type .
|
inlineexplicit |
Constructs a choice
messaging block.
_Tuple | A tuple of sources for the choice. |
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.
|
inline |
Constructs a choice
messaging block.
_Choice | A choice 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.
|
inline |
Destroys the choice
messaging block.
|
private |
|
inlineprivate |
Deletes all _Reserving_node elements that were created in _Initialize_choices.
The highest-number index of the choice's sources
|
inlineprivate |
|
inlineprivate |
Constructs and initializes a _Reserving_node for each tuple messaging block passed in.
The highest-number index of the choice's sources
|
inlineprivate |
|
inlinevirtual |
Accepts a message that was offered by this choice
block, transferring ownership to the caller.
_MsgId | The runtime_object_identity of the offered message object. |
_PTarget | A pointer to the target block that is calling the accept method. |
Implements Concurrency::ISource< size_t >.
|
inlinevirtual |
Acquires a reference count on this choice
messaging block, to prevent deletion.
_PTarget | A 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.
Implements Concurrency::ISource< size_t >.
|
inlinevirtual |
Consumes a message previously offered by this choice
messaging block and successfully reserved by the target, transferring ownership to the caller.
_MsgId | The runtime_object_identity of the reserved message object. |
_PTarget | A pointer to the target block that is calling the consume method. |
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
.
Implements Concurrency::ISource< size_t >.
|
inline |
Checks whether this choice
messaging block has been initialized with a value yet.
true
if the block has received a value, false
otherwise.
|
inline |
Returns an index into the tuple
representing the element selected by the choice
messaging block.
The message payload can be extracted using the get
method.
|
inlinevirtual |
Links a target block to this choice
messaging block.
_PTarget | A pointer to an ITarget block to link to this choice messaging block. |
Implements Concurrency::ISource< size_t >.
|
private |
|
inlinevirtual |
Releases a previous successful message reservation.
_MsgId | The runtime_object_identity of the message object being released. |
_PTarget | A pointer to the target block that is calling the release method. |
Implements Concurrency::ISource< size_t >.
|
inlinevirtual |
Releases a reference count on this choice
messaging block.
_PTarget | A 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.
Implements Concurrency::ISource< size_t >.
|
inlinevirtual |
Reserves a message previously offered by this choice
messaging block.
_MsgId | The runtime_object_identity of the message object being reserved. |
_PTarget | A pointer to the target block that is calling the reserve method. |
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.
Implements Concurrency::ISource< size_t >.
|
inlinevirtual |
Unlinks a target block from this choice
messaging block.
_PTarget | A pointer to an ITarget block to unlink from this choice messaging block. |
Implements Concurrency::ISource< size_t >.
|
inlinevirtual |
Unlinks all targets from this choice
messaging block.
This method does not need to be called from the destructor because destructor for the internal single_assignment
block will unlink properly.
Implements Concurrency::ISource< size_t >.
|
inline |
Gets the message whose index was selected by the choice
messaging block.
_Payload_type | The type of the message payload. |
Because a choice
messaging block can take inputs with different payload types, you must specify the type of the payload at the point of retrieval. You can determine the type based on the result of the index
method.
|
private |
|
private |
|
private |
|
private |
|
private |