priority_queue_node¶
[flow_graph.priority_queue_node]
A class template that forwards messages in priority order by maintaining a buffer of messages.
// Defined in header <tbb/flow_graph.h>
namespace tbb {
namespace flow {
template< typename T, typename Compare = std::less<T>>
class priority_queue_node : public graph_node, public receiver<T>, public sender<T> {
public:
typedef size_t size_type;
explicit priority_queue_node( graph &g );
priority_queue_node( const priority_queue_node &src );
~priority_queue_node();
bool try_put( const T &v );
bool try_get( T &v );
};
} // namespace flow
} // namespace tbb
Requirements:
The type
Tshall meet the CopyConstructible requirements from [copyconstructible] and CopyAssignable requirements from [copyassignable] ISO C++ Standard sections.The type
Compareshall meet the Compare type requirements from [alg.sorting] ISO C++ Standard section. IfCompareinstance throws an exception, then behavior is undefined.
The next message to be forwarded has the largest priority as determined by Compare template argument.
priority_queue_node is a graph_node, receiver<T> and sender<T>.
priority_queue_node has a buffering and single-push properties.
Member functions¶
-
explicit
priority_queue_node(graph &g)¶ Constructs an empty
priority_queue_nodethat belongs to the graphg.
-
priority_queue_node(const priority_queue_node &src)¶ Constructs an empty
priority_queue_nodethat belongs to the same graphgassrc. The list of predecessors, the list of successors and the messages in the buffer are not copied.
-
bool
try_put(const T &v) Adds
vto thepriority_queue_node. Ifv’s priority is the largest of all of the currently buffered messages, a task is spawned to forward the item to a successor.Returns:
true
-
bool
try_put(T &v)¶ Returns:
trueif a message is available in the node and the node is not currently reserved. Otherwise returnsfalse. If the node returnstrue, the message with the largest priority will have been copied tov.
Example¶
Usage scenario is similar to sequencer_node except that the
priority_queue_node provides local order, passing the message with highest priority of all
stored at the moment, while sequencer_node enforces global order and does not allow a
“smaller priority” message to pass through before all its preceding messages.