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::overwrite_buffer< _Type > Class Template Reference

An overwrite_buffer messaging block is a multi-target, multi-source, ordered propagator_block capable of storing a single message at a time. New messages overwrite previously held ones. More...

#include <agents.h>

Inheritance diagram for Concurrency::overwrite_buffer< _Type >:
Concurrency::propagator_block< multi_link_registry< ITarget< _Type > >, multi_link_registry< ISource< _Type > > > Concurrency::source_block< multi_link_registry< ITarget< _Type > >, _MessageProcessorType > Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type > Concurrency::ISource< multi_link_registry< ITarget< _Type > >::type::type >

Public Member Functions

 overwrite_buffer ()
 Constructs an overwrite_buffer messaging block. More...
 
 overwrite_buffer (filter_method const &_Filter)
 Constructs an overwrite_buffer messaging block. More...
 
 ~overwrite_buffer ()
 Destroys the overwrite_buffer messaging block. More...
 
bool has_value () const
 Checks whether this overwrite_buffer messaging block has a value yet. More...
 
_Type value ()
 Gets a reference to the current payload of the message being stored in the overwrite_buffer messaging block. More...
 
- Public Member Functions inherited from Concurrency::propagator_block< multi_link_registry< ITarget< _Type > >, multi_link_registry< ISource< _Type > > >
 propagator_block ()
 Constructs a propagator_block object. More...
 
virtual ~propagator_block ()
 Destroys a propagator_block object. More...
 
virtual message_status propagate (_Inout_opt_ message< _Source_type > *_PMessage, _Inout_opt_ ISource< _Source_type > *_PSource)
 Asynchronously passes a message from a source block to this target block. More...
 
virtual message_status send (_Inout_ message< _Source_type > *_PMessage, _Inout_ ISource< _Source_type > *_PSource)
 Synchronously initiates a message to this block. Called by an ISource block. When this function completes, the message will already have propagated into the block. More...
 
- Public Member Functions inherited from Concurrency::source_block< multi_link_registry< ITarget< _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< multi_link_registry< ITarget< _Type > >::type::type >
virtual ~ISource ()
 Destroys the ISource object. More...
 
virtual void link_target (_Inout_ ITarget< multi_link_registry< ITarget< _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< multi_link_registry< ITarget< _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< multi_link_registry< ITarget< _Type > >::type::type > * accept (runtime_object_identity _MsgId, _Inout_ ITarget< multi_link_registry< ITarget< _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< multi_link_registry< ITarget< _Type > >::type::type > *_PTarget)=0
 When overridden in a derived class, reserves a message previously offered by this ISource block. More...
 
virtual message< multi_link_registry< ITarget< _Type > >::type::type > * consume (runtime_object_identity _MsgId, _Inout_ ITarget< multi_link_registry< ITarget< _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< multi_link_registry< ITarget< _Type > >::type::type > *_PTarget)=0
 When overridden in a derived class, releases a previous successful message reservation. More...
 
virtual void acquire_ref (_Inout_ ITarget< multi_link_registry< ITarget< _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< multi_link_registry< ITarget< _Type > >::type::type > *_PTarget)=0
 When overridden in a derived class, releases a reference count on this ISource block. More...
 
- Public Member Functions inherited from Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type >
virtual ~ITarget ()
 Destroys the ITarget object. More...
 
virtual message_status propagate (_Inout_opt_ message< multi_link_registry< ISource< _Type > >::type::source_type > *_PMessage, _Inout_opt_ ISource< multi_link_registry< ISource< _Type > >::type::source_type > *_PSource)=0
 When overridden in a derived class, asynchronously passes a message from a source block to this target block. More...
 
virtual message_status send (_Inout_ message< multi_link_registry< ISource< _Type > >::type::source_type > *_PMessage, _Inout_ ISource< multi_link_registry< ISource< _Type > >::type::source_type > *_PSource)=0
 When overridden in a derived class, synchronously passes a message to the target block. More...
 

Protected Member Functions

virtual message_status propagate_message (_Inout_ message< _Type > *_PMessage, _Inout_ ISource< _Type > *_PSource)
 Asynchronously passes a message from an ISource block to this overwrite_buffer messaging block. It is invoked by the propagate method, when called by a source block. More...
 
virtual message_status send_message (_Inout_ message< _Type > *_PMessage, _Inout_ ISource< _Type > *_PSource)
 Synchronously passes a message from an ISource block to this overwrite_buffer messaging block. It is invoked by the send method, when called by a source block. More...
 
virtual bool supports_anonymous_source ()
 Overrides the supports_anonymous_source method to indicate that this block can accept messages offered to it by a source that is not linked. More...
 
virtual message< _Type > * accept_message (runtime_object_identity _MsgId)
 Accepts a message that was offered by this overwrite_buffer messaging block, returning a copy of the message to the caller. More...
 
virtual bool reserve_message (runtime_object_identity _MsgId)
 Reserves a message previously offered by this overwrite_buffer messaging block. More...
 
virtual message< _Type > * consume_message (runtime_object_identity _MsgId)
 Consumes a message previously offered by the overwrite_buffer messaging block and reserved by the target, returning a copy of the message 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< _Type > *_PTarget)
 A callback that notifies that a new target has been linked to this overwrite_buffer messaging block. More...
 
virtual void propagate_to_any_targets (_Inout_ message< _Type > *_PMessage)
 Places the message _PMessage in this overwrite_buffer messaging block and offers it to all of the linked targets. More...
 
- Protected Member Functions inherited from Concurrency::propagator_block< multi_link_registry< ITarget< _Type > >, multi_link_registry< ISource< _Type > > >
virtual message_status propagate_message (_Inout_ message< _Source_type > *_PMessage, _Inout_ ISource< _Source_type > *_PSource)=0
 When overridden in a derived class, this method asynchronously passes a message from an ISource block to this propagator_block object. It is invoked by the propagate method, when called by a source block. More...
 
virtual message_status send_message (_Inout_ message< _Source_type > *, _Inout_ ISource< _Source_type > *)
 When overridden in a derived class, this method synchronously passes a message from an ISource block to this propagator_block object. It is invoked by the send method, when called by a source block. More...
 
virtual void link_source (_Inout_ ISource< _Source_type > *_PSource)
 Links a specified source block to this propagator_block object. More...
 
virtual void unlink_source (_Inout_ ISource< _Source_type > *_PSource)
 Unlinks a specified source block from this propagator_block object. More...
 
virtual void unlink_sources ()
 Unlinks all source blocks from this propagator_block object. More...
 
virtual void process_input_messages (_Inout_ message< _Target_type > *)
 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< multi_link_registry< ITarget< _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< multi_link_registry< ITarget< _Type > >::type::type >
void _Invoke_link_source (ITarget< multi_link_registry< ITarget< _Type > >::type::type > *_PLinkFrom)
 Links this source to a target. More...
 
void _Invoke_unlink_source (ITarget< multi_link_registry< ITarget< _Type > >::type::type > *_PUnlinkFrom)
 Unlinks this source from a target. More...
 
- Protected Member Functions inherited from Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type >
virtual void link_source (_Inout_ ISource< multi_link_registry< ISource< _Type > >::type::source_type > *_PSource)=0
 When overridden in a derived class, links a specified source block to this ITarget block. More...
 
virtual void unlink_source (_Inout_ ISource< multi_link_registry< ISource< _Type > >::type::source_type > *_PSource)=0
 When overridden in a derived class, unlinks a specified source block from this ITarget block. More...
 

Private Types

typedef multi_link_registry< ITarget< _Type > > _TargetLinkRegistry
 
typedef multi_link_registry< ISource< _Type > > _SourceLinkRegistry
 

Private Member Functions

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...
 
overwrite_buffer const & operator= (overwrite_buffer const &)
 
 overwrite_buffer (overwrite_buffer const &)
 

Private Attributes

message< _Type > * _M_pMessage
 
message< _Type > * _M_pReservedMessage
 
volatile bool _M_fIsInitialized
 

Additional Inherited Members

- Public Types inherited from Concurrency::propagator_block< multi_link_registry< ITarget< _Type > >, multi_link_registry< ISource< _Type > > >
typedef multi_link_registry< ISource< _Type > >::type::source_type _Source_type
 The type of the payload for the incoming message to this propagator_block. More...
 
typedef source_link_manager< multi_link_registry< ISource< _Type > > > _SourceLinkManager
 The type of the source_link_manager this propagator_block. More...
 
typedef _SourceLinkManager::iterator source_iterator
 The type of the iterator for the source_link_manager for this propagator_block. More...
 
- Public Types inherited from Concurrency::source_block< multi_link_registry< ITarget< _Type > >, _MessageProcessorType >
typedef multi_link_registry< ITarget< _Type > >::type::type _Target_type
 The payload type of messages handled by this source_block. More...
 
typedef multi_link_registry< ITarget< _Type > >::iterator target_iterator
 The iterator to walk the connected targets. More...
 
- Public Types inherited from Concurrency::ISource< multi_link_registry< ITarget< _Type > >::type::type >
typedef multi_link_registry< ITarget< _Type > >::type::type source_type
 A type alias for _Type . More...
 
- Public Types inherited from Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type >
typedef multi_link_registry< ISource< _Type > >::type::source_type type
 A type alias for _Type . More...
 
typedef std::function< bool(multi_link_registry< ISource< _Type > >::type::source_typeconst &)> filter_method
 The signature of any method used by the block that returns a bool value to determine whether an offered message should be accepted. More...
 
- Protected Attributes inherited from Concurrency::propagator_block< multi_link_registry< ITarget< _Type > >, multi_link_registry< ISource< _Type > > >
_SourceLinkManager _M_connectedSources
 The container for all the sources connected to this block. More...
 
filter_method_M_pFilter
 The filter function which determines whether offered messages should be accepted. More...
 
volatile bool _M_fDeclineMessages
 A bool that is set to indicate that all messages should be declined in preparation for deleting the block More...
 
- Protected Attributes inherited from Concurrency::source_block< multi_link_registry< ITarget< _Type > >, _MessageProcessorType >
ITarget< _Target_type > * _M_pReservedFor
 Connected target that is holding a reservation More...
 
runtime_object_identity _M_reservedId
 Reserved message ID More...
 
multi_link_registry< ITarget< _Type > > _M_connectedTargets
 Connected targets More...
 
_MessageProcessorType _M_messageProcessor
 Processor used for asynchronous message handling More...
 

Detailed Description

template<class _Type>
class Concurrency::overwrite_buffer< _Type >

An overwrite_buffer messaging block is a multi-target, multi-source, ordered propagator_block capable of storing a single message at a time. New messages overwrite previously held ones.

Template Parameters
_TypeThe payload type of the messages stored and propagated by the buffer.

An overwrite_buffer messaging block propagates out copies of its stored message to each of its targets.

For more information, see Asynchronous Message Blocks.

See also
unbounded_buffer Class, single_assignment Class

Member Typedef Documentation

Constructor & Destructor Documentation

template<class _Type>
Concurrency::overwrite_buffer< _Type >::overwrite_buffer ( )
inline

Constructs an overwrite_buffer messaging block.

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

The type filter_method is a functor with signature bool (_Type const &) which is invoked by this overwrite_buffer messaging block to determine whether or not it should accept an offered message.

See also
Scheduler Class, ScheduleGroup Class
6550  :
6552  {
6554  }
message< _Type > * _M_pMessage
Definition: agents.h:7076
message< _Type > * _M_pReservedMessage
Definition: agents.h:7079
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:5827
volatile bool _M_fIsInitialized
Definition: agents.h:7082
#define NULL
Definition: corecrt.h:158
template<class _Type>
Concurrency::overwrite_buffer< _Type >::overwrite_buffer ( filter_method const &  _Filter)
inline

Constructs an overwrite_buffer messaging block.

Parameters
_FilterA filter function which determines whether offered messages should be accepted.

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

The type filter_method is a functor with signature bool (_Type const &) which is invoked by this overwrite_buffer messaging block to determine whether or not it should accept an offered message.

See also
Scheduler Class, ScheduleGroup Class
6572  :
6574  {
6576  this->register_filter(_Filter);
6577  }
message< _Type > * _M_pMessage
Definition: agents.h:7076
message< _Type > * _M_pReservedMessage
Definition: agents.h:7079
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:5827
void register_filter(filter_method const &_Filter)
Registers a filter method that will be invoked on every received message.
Definition: agents.h:5842
volatile bool _M_fIsInitialized
Definition: agents.h:7082
#define NULL
Definition: corecrt.h:158
template<class _Type>
Concurrency::overwrite_buffer< _Type >::~overwrite_buffer ( )
inline

Destroys the overwrite_buffer messaging block.

6686  {
6687  // Remove all links that are targets of this overwrite_buffer
6688  this->remove_network_links();
6689 
6690  // Clean up any messages left in this message block
6692  }
void _Delete_stored_messages()
Deletes all messages currently stored in this message block. Should be called by the destructor to en...
Definition: agents.h:7044
void remove_network_links()
Removes all the source and target network links from this propagator_block object.
Definition: agents.h:5866
template<class _Type>
Concurrency::overwrite_buffer< _Type >::overwrite_buffer ( overwrite_buffer< _Type > const &  )
private

Member Function Documentation

template<class _Type>
void Concurrency::overwrite_buffer< _Type >::_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.

7045  {
7046  // Input messages for this message block are in the base-class input buffer
7047  // All messages in that buffer are guaranteed to have moved to the output
7048  // buffer because the destructor first waits for all async sends to finish
7049  // before reaching this point
7050 
7051  // The messages for an overwrite buffer are deleted when overwritten
7052  // through reference counting. This final check is put in place in
7053  // case any message still exists in the buffer when the overwrite_buffer
7054  // is deleted. The reference count of this message has not yet reached
7055  // zero because it hasn't been overwritten yet. It is safe because of
7056  // we have finished all propagation.
7057  if (_M_pMessage != NULL)
7058  {
7059  // A block can only have a reserved message after receiving a message
7060  // at some point, so it must be within the above if-clause.
7061  // Now delete the reserved message if it is non-NULL and different from
7062  // the saved internal message
7064  {
7065  delete _M_pReservedMessage;
7066  }
7067  delete _M_pMessage;
7068  }
7069  }
message< _Type > * _M_pMessage
Definition: agents.h:7076
message< _Type > * _M_pReservedMessage
Definition: agents.h:7079
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual message<_Type>* Concurrency::overwrite_buffer< _Type >::accept_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Accepts a message that was offered by this overwrite_buffer messaging block, returning a copy of the message to the caller.

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

The overwrite_buffer messaging block returns copies of the message to its targets, rather than transferring ownership of the currently held message.

Implements Concurrency::source_block< multi_link_registry< ITarget< _Type > >, _MessageProcessorType >.

6840  {
6841  //
6842  // If the internal message has not yet been initialized yet, return NULL
6843  //
6844  if (_M_pMessage == NULL)
6845  {
6846  return NULL;
6847  }
6848 
6849  //
6850  // Instead of returning the internal message, we return a copy of the
6851  // message stored.
6852  //
6853  // Because we are returning a copy, the accept routine for an overwritebuffer
6854  // does not need to grab the internalLock
6855  //
6856  message<_Type> * _Msg = NULL;
6857  if (_M_pMessage->msg_id() == _MsgId)
6858  {
6859  _Msg = new message<_Type>(_M_pMessage->payload);
6860  }
6861 
6862  return _Msg;
6863  }
message< _Type > * _M_pMessage
Definition: agents.h:7076
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual message<_Type>* Concurrency::overwrite_buffer< _Type >::consume_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Consumes a message previously offered by the overwrite_buffer messaging block and reserved by the target, returning a copy of the message to the caller.

Parameters
_MsgIdThe runtime_object_identity of the message object being consumed.
Returns
A pointer to the message object that the caller now has ownership of.

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

Implements Concurrency::source_block< multi_link_registry< ITarget< _Type > >, _MessageProcessorType >.

6915  {
6916  // Leave and return NULL if this msgId doesn't match the reserved message
6917  // Otherwise this is a pull of a later overwritten message, and messages
6918  // could them appear out of order.
6919  if (_M_pReservedMessage != NULL && _M_pReservedMessage->msg_id() != _MsgId)
6920  {
6921  return NULL;
6922  }
6923  // This redundant assert is specifically to make the /analyze switch happy, which cannot recognize the same assertion above in if stmnt.
6925 
6926  _Type _Payload = _M_pReservedMessage->payload;
6927 
6928  // Take the reserved message
6929  message<_Type> * _Result = new message<_Type>(_Payload);
6930 
6931  if (_M_pReservedMessage->remove_ref() == 0)
6932  {
6933  delete _M_pReservedMessage;
6934  }
6936 
6937  return _Result;
6938  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
_In_ wctype_t _Type
Definition: corecrt_wctype.h:111
message< _Type > * _M_pReservedMessage
Definition: agents.h:7079
_Result
Definition: corecrt_wconio.h:362
#define NULL
Definition: corecrt.h:158
template<class _Type>
bool Concurrency::overwrite_buffer< _Type >::has_value ( ) const
inline

Checks whether this overwrite_buffer messaging block has a value yet.

Returns
true if the block has received a value, false otherwise.
6702  {
6703  return _M_fIsInitialized != 0;
6704  }
volatile bool _M_fIsInitialized
Definition: agents.h:7082
template<class _Type>
virtual void Concurrency::overwrite_buffer< _Type >::link_target_notification ( _Inout_ ITarget< _Type > *  _PTarget)
inlineprotectedvirtual

A callback that notifies that a new target has been linked to this overwrite_buffer messaging block.

Parameters
_PTargetA pointer to the newly linked target.
6982  {
6983  // If there is a message available already, propagate it
6984  if (_M_pMessage != NULL)
6985  {
6986  _PTarget->propagate(_M_pMessage, this);
6987  }
6988  }
message< _Type > * _M_pMessage
Definition: agents.h:7076
#define NULL
Definition: corecrt.h:158
template<class _Type>
overwrite_buffer const& Concurrency::overwrite_buffer< _Type >::operator= ( overwrite_buffer< _Type > const &  )
private
template<class _Type>
virtual message_status Concurrency::overwrite_buffer< _Type >::propagate_message ( _Inout_ message< _Type > *  _PMessage,
_Inout_ ISource< _Type > *  _PSource 
)
inlineprotectedvirtual

Asynchronously passes a message from an ISource block to this overwrite_buffer messaging block. It is invoked by the propagate method, when called by a source block.

Parameters
_PMessageA pointer to the message object.
_PSourceA pointer to the source block offering the message.
Returns
A message_status indication of what the target decided to do with the message.
6744  {
6745  // It is important that calls to propagate do *not* take the same lock on the
6746  // internal structure that is used by Consume and the LWT. Doing so could
6747  // result in a deadlock with the Consume call.
6748 
6750 
6751  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
6752 
6753  //
6754  // If message was accepted, set the member variables for
6755  // this block and start the asynchronous propagation task
6756  //
6757  if (_PMessage != NULL)
6758  {
6759  // Add a reference for the async_send holding the message
6760  _PMessage->add_ref();
6761 
6762  this->async_send(_PMessage);
6763  }
6764  else
6765  {
6766  _Result = missed;
6767  }
6768 
6769  return _Result;
6770  }
message_status
The valid responses for an offer of a message object to a block.
Definition: agents.h:1740
The target tried to accept the message, but it was no longer available.
Definition: agents.h:1761
The target accepted the message.
Definition: agents.h:1746
_Pre_maybenull_ _Inout_ _Deref_prepost_z_ wchar_t const _PSource
Definition: wchar.h:148
_Result
Definition: corecrt_wconio.h:362
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:5435
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual void Concurrency::overwrite_buffer< _Type >::propagate_to_any_targets ( _Inout_ message< _Type > *  _PMessage)
inlineprotectedvirtual

Places the message _PMessage in this overwrite_buffer messaging block and offers it to all of the linked targets.

Parameters
_PMessageA pointer to a message object that this overwrite_buffer has taken ownership of.

This method overwrites the current message in the overwrite_buffer with the newly accepted message _PMessage .

7003  {
7004  // Move the message from the queuedMessages Buffer to the internal storage
7005 
7006  // Add a reference for the overwrite_buffer holding the message
7007  _PMessage->add_ref();
7008 
7009  if (_M_pMessage != NULL)
7010  {
7011  if (_M_pMessage->remove_ref() == 0)
7012  {
7013  delete _M_pMessage;
7014  }
7015  }
7016 
7017  _M_pMessage = _PMessage;
7018 
7019  // Now that message has been received, set this block as initialized
7020  _M_fIsInitialized = true;
7021 
7022  for (target_iterator _Iter = this->_M_connectedTargets.begin(); *_Iter != NULL; ++_Iter)
7023  {
7024  // Overwrite buffers can propagate its message out
7025  // to any number of Targets
7026 
7027  ITarget<_Type> * _PTarget = *_Iter;
7028  _PTarget->propagate(_PMessage, this);
7029  }
7030 
7031  if (_PMessage->remove_ref() == 0)
7032  {
7033  delete _PMessage;
7034  }
7035  }
multi_link_registry< ITarget< _Type > >::iterator target_iterator
The iterator to walk the connected targets.
Definition: agents.h:4893
multi_link_registry< ITarget< _Type > > _M_connectedTargets
Connected targets
Definition: agents.h:5485
message< _Type > * _M_pMessage
Definition: agents.h:7076
volatile bool _M_fIsInitialized
Definition: agents.h:7082
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual void Concurrency::overwrite_buffer< _Type >::release_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Releases a previous message reservation.

Parameters
_MsgIdThe runtime_object_identity of the message object being released.

Implements Concurrency::source_block< multi_link_registry< ITarget< _Type > >, _MessageProcessorType >.

6948  {
6951 
6952  if (_MsgId != _M_pReservedMessage->msg_id())
6953  {
6954  throw message_not_found();
6955  }
6956 
6957  if (_M_pReservedMessage->remove_ref() == 0)
6958  {
6959  delete _M_pReservedMessage;
6960  }
6962  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
message< _Type > * _M_pReservedMessage
Definition: agents.h:7079
volatile bool _M_fIsInitialized
Definition: agents.h:7082
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual bool Concurrency::overwrite_buffer< _Type >::reserve_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Reserves a message previously offered by this overwrite_buffer messaging block.

Parameters
_MsgIdThe runtime_object_identity of the message object being reserved.
Returns
true if the message was successfully reserved, false otherwise.

After reserve is called, if it returns true, either consume or release must be called to either take or release ownership of the message.

Implements Concurrency::source_block< multi_link_registry< ITarget< _Type > >, _MessageProcessorType >.

6880  {
6881  // Ensure that this message currently exists in the overwrite buffer
6882  if (_M_pMessage == NULL || _M_pMessage->msg_id() != _MsgId)
6883  {
6884  return false;
6885  }
6886 
6887  // Can only reserve one message, any other blocks trying to reserve
6888  // will return false
6890 
6891  // Save this message away
6893 
6894  // Add a reference for this message to prevent deletion
6895  _M_pReservedMessage->add_ref();
6896 
6897  return true;
6898  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
message< _Type > * _M_pMessage
Definition: agents.h:7076
message< _Type > * _M_pReservedMessage
Definition: agents.h:7079
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual void Concurrency::overwrite_buffer< _Type >::resume_propagation ( )
inlineprotectedvirtual

Resumes propagation after a reservation has been released.

Implements Concurrency::source_block< multi_link_registry< ITarget< _Type > >, _MessageProcessorType >.

6969  {
6970  // On reservation we do not stop propagation. So there
6971  // is nothing to be done to resume propagation.
6972  }
template<class _Type>
virtual message_status Concurrency::overwrite_buffer< _Type >::send_message ( _Inout_ message< _Type > *  _PMessage,
_Inout_ ISource< _Type > *  _PSource 
)
inlineprotectedvirtual

Synchronously passes a message from an ISource block to this overwrite_buffer messaging block. It is invoked by the send 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.
6788  {
6789  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
6790 
6791  //
6792  // If message was accepted, set the member variables for
6793  // this block and start the asynchronous propagation task
6794  //
6795  if (_PMessage != NULL)
6796  {
6797  // Add a reference for the sync_send holding the message
6798  _PMessage->add_ref();
6799 
6800  this->sync_send(_PMessage);
6801  }
6802  else
6803  {
6804  return missed;
6805  }
6806 
6807  return accepted;
6808  }
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...
Definition: agents.h:5421
The target tried to accept the message, but it was no longer available.
Definition: agents.h:1761
The target accepted the message.
Definition: agents.h:1746
_Pre_maybenull_ _Inout_ _Deref_prepost_z_ wchar_t const _PSource
Definition: wchar.h:148
#define NULL
Definition: corecrt.h:158
template<class _Type>
virtual bool Concurrency::overwrite_buffer< _Type >::supports_anonymous_source ( )
inlineprotectedvirtual

Overrides the supports_anonymous_source method to indicate that this block can accept messages offered to it by a source that is not linked.

Returns
true because the block does not postpone offered messages.

Reimplemented from Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type >.

6819  {
6820  return true;
6821  }
template<class _Type>
_Type Concurrency::overwrite_buffer< _Type >::value ( )
inline

Gets a reference to the current payload of the message being stored in the overwrite_buffer messaging block.

Returns
The payload of the currently stored message.

The value stored in the overwrite_buffer could change immediately after this method returns. This method will wait until a message arrives if no message is currently stored in the overwrite_buffer.

6718  {
6719  return ::Concurrency::receive<_Type>(this);
6720  }

Member Data Documentation

template<class _Type>
volatile bool Concurrency::overwrite_buffer< _Type >::_M_fIsInitialized
private
template<class _Type>
message<_Type>* Concurrency::overwrite_buffer< _Type >::_M_pMessage
private
template<class _Type>
message<_Type>* Concurrency::overwrite_buffer< _Type >::_M_pReservedMessage
private

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