A template class that is a graph_node, receiver<Input> and sender<Output>. A write_once_node represents a buffer of a single item that cannot be over-written. The first put to the node sets the value. The value may be cleared explicitly, after which a new value may be set. Gets from the node are non-destructive.
Rejection of messages by successors is handled using the protocol in the Message Passing Protocol, see link below.
T must be copy-constructible and assignable
template < typename T > class write_once_node;
#include "tbb/flow_graph.h"
namespace tbb {
namespace flow {
template< typename T >
class write_once_node :
public graph_node, public receiver<T>,
public sender<T> {
public:
write_once_node( graph &g );
write_once_node( const write_once_node &src );
// receiver<T>
typedef T input_type;
typedef sender<input_type> predecessor_type;
bool try_put( const input_type &v );
bool register_predecessor( predecessor_type &p );
bool remove_predecessor( predecessor_type &p );
// sender<T>
typedef T output_type;
typedef receiver<output_type> successor_type;
bool register_successor( successor_type &r );
bool remove_successor( successor_type &r );
bool try_get( output_type &v );
bool try_reserve( output_type &v );
bool try_release( );
bool try_consume( );
bool is_valid( );
void clear( );
};
}
}
| Member | Description |
|---|---|
| write_once_node( graph &g ) |
Constructs an object of type write_once_node that belongs to the graph g, with an invalid internal buffer item. |
| write_once_node( const write_once_node &src ) |
Constructs an object of type write_once_node with an invalid internal buffer item. The buffered value and list of successors is NOT copied from src. |
| bool try_put( const input_type &v ) |
Stores v in the internal single item buffer if it does not already contain a valid value. If a new value is set, it calls try_put(v) on all successors. Returns: true |
| bool register_predecessor( predecessor_type &p ) |
Never rejects puts and therefore does not need to maintain a list of predecessors. Returns: false |
| bool remove_predecessor( predecessor_type &p ) |
Never rejects puts and therefore does not need to maintain a list of predecessors. Returns: false |
| bool register_successor( successor_type &r ) |
Adds r to the set of successors. If a valid item v is held in the buffer, a task is spawned to call r.try_put(v). Returns: true |
| bool remove_successor( successor_type &r ) |
Removes r from the set of successors. Returns: true |
| bool try_get( output_type &v ) |
If the internal buffer is valid, assigns the value to v. Returns: true if v is assigned to. false if v is not assigned to. |
| bool try_reserve( output_type &v ) |
Does not support reservations. Returns: false |
| bool try_release( ) |
Does not support reservations. Returns: false |
| bool try_consume( ) |
Does not support reservations. Returns: false |
| bool is_valid( ) |
Returns: true if the buffer holds a valid value, otherwise returns false. |
| void clear( ) |
Invalidates the value held in the buffer. |