17 #ifndef __TBB_flow_graph_impl_H 18 #define __TBB_flow_graph_impl_H 20 #include "../tbb_stddef.h" 22 #include "../task_arena.h" 23 #include "../flow_graph_abstractions.h" 25 #if __TBB_PREVIEW_FLOW_GRAPH_PRIORITIES 26 #include "../concurrent_priority_queue.h" 31 #if TBB_DEPRECATED_FLOW_ENQUEUE 32 #define FLOW_SPAWN(a) tbb::task::enqueue((a)) 34 #define FLOW_SPAWN(a) tbb::task::spawn((a)) 37 #if __TBB_PREVIEW_FLOW_GRAPH_PRIORITIES 38 #define __TBB_FLOW_GRAPH_PRIORITY_EXPR( expr ) expr 39 #define __TBB_FLOW_GRAPH_PRIORITY_ARG0( priority ) , priority 40 #define __TBB_FLOW_GRAPH_PRIORITY_ARG1( arg1, priority ) arg1, priority 42 #define __TBB_FLOW_GRAPH_PRIORITY_EXPR( expr ) 43 #define __TBB_FLOW_GRAPH_PRIORITY_ARG0( priority ) 44 #define __TBB_FLOW_GRAPH_PRIORITY_ARG1( arg1, priority ) arg1 45 #endif // __TBB_PREVIEW_FLOW_GRAPH_PRIORITIES 47 #if TBB_DEPRECATED_LIMITER_NODE_CONSTRUCTOR 48 #define __TBB_DEPRECATED_LIMITER_EXPR( expr ) expr 49 #define __TBB_DEPRECATED_LIMITER_ARG2( arg1, arg2 ) arg1, arg2 50 #define __TBB_DEPRECATED_LIMITER_ARG4( arg1, arg2, arg3, arg4 ) arg1, arg3, arg4 52 #define __TBB_DEPRECATED_LIMITER_EXPR( expr ) 53 #define __TBB_DEPRECATED_LIMITER_ARG2( arg1, arg2 ) arg1 54 #define __TBB_DEPRECATED_LIMITER_ARG4( arg1, arg2, arg3, arg4 ) arg1, arg2 55 #endif // TBB_DEPRECATED_LIMITER_NODE_CONSTRUCTOR 62 #if __TBB_PREVIEW_FLOW_GRAPH_PRIORITIES 68 namespace interface10 {
72 namespace interface11 {
76 #if __TBB_PREVIEW_FLOW_GRAPH_PRIORITIES 90 template <
typename GraphContainerType,
typename GraphNodeType>
107 my_graph(other.my_graph), current_node(other.current_node)
112 if (
this != &other) {
120 reference operator*()
const;
123 pointer operator->()
const;
154 void internal_forward();
174 #if __TBB_PREVIEW_FLOW_GRAPH_PRIORITIES 176 bool operator()(
const graph_task* left,
const graph_task* right) {
186 : my_priority_queue(priority_queue) {}
188 graph_task* t = NULL;
189 bool result = my_priority_queue.try_pop(t);
190 __TBB_ASSERT_EX( result,
"Number of critical tasks for scheduler and tasks" 191 " in graph's priority queue mismatched" );
193 "Incorrect task submitted to graph priority queue" );
195 "Tasks from graph's priority queue must have priority" );
208 namespace interface10 {
214 template<
typename Body >
220 ) :
tbb::flow::interface11::graph_task(node_priority),
233 template<
typename Receiver,
typename Body >
238 tbb::task *res = my_receiver.try_put_task(my_body());
268 my_task_arena->terminate();
272 __TBB_ASSERT(my_task_arena == NULL,
"task arena is not NULL");
275 if (!my_task_arena->is_active())
276 my_task_arena->initialize();
277 __TBB_ASSERT(my_task_arena->is_active(),
"task arena is not active");
291 #if TBB_PREVIEW_FLOW_GRAPH_TRACE 292 void set_name(
const char *
name);
316 template<
typename Receiver,
typename Body >
317 void run(Receiver &r, Body body) {
319 task* rtask =
new (task::allocate_additional_child_of(*
root_task()))
328 template<
typename Body >
340 caught_exception =
false;
342 #if TBB_USE_EXCEPTIONS 346 #if __TBB_TASK_GROUP_CONTEXT 347 cancelled = my_context->is_group_execution_cancelled();
349 #if TBB_USE_EXCEPTIONS 352 my_root_task->set_ref_count(1);
354 caught_exception =
true;
359 #if __TBB_TASK_GROUP_CONTEXT 366 my_root_task->set_ref_count(1);
367 #if __TBB_TASK_GROUP_CONTEXT 379 template<
typename C,
typename N>
392 const_iterator
begin()
const;
394 const_iterator
end()
const;
396 const_iterator cbegin()
const;
398 const_iterator cend()
const;
409 #if __TBB_TASK_GROUP_CONTEXT 426 #if __TBB_PREVIEW_FLOW_GRAPH_PRIORITIES 443 namespace interface11 {
447 #if __TBB_PREVIEW_FLOW_GRAPH_NODE_SET 449 class get_graph_helper;
456 template<
typename C,
typename N>
459 #if __TBB_PREVIEW_FLOW_GRAPH_NODE_SET 460 friend class internal::get_graph_helper;
471 #if TBB_PREVIEW_FLOW_GRAPH_TRACE 472 virtual void set_name(
const char *
name) = 0;
475 #if TBB_DEPRECATED_FLOW_NODE_EXTRACTION 476 virtual void extract() = 0;
498 #if __TBB_PREVIEW_FLOW_GRAPH_PRIORITIES 500 task* critical_task = &t;
512 return *critical_task;
547 #endif // __TBB_flow_graph_impl_H
tbb::task_group_context * my_context
void wait_for_all()
Wait until graph is idle and decrement_wait_count calls equals increment_wait_count calls...
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp end
Base class for types that should not be assigned.
void add_task_to_graph_reset_list(tbb::flow::interface10::graph &g, tbb::task *tp)
graph_task_priority_queue_t & my_priority_queue
void decrement_wait_count()
tbb::task * execute() __TBB_override
Should be overridden by derived classes.
void prepare_task_arena(bool reinit=false)
tbb::task * graph_root_task
bool operator==(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
bool operator!=(const graph_iterator &other) const
Inequality.
bool is_graph_active(tbb::flow::interface10::graph &g)
static const node_priority_t no_priority
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp begin
void run(Receiver &r, Body body)
Spawns a task that runs a body and puts its output to a specific receiver.
tbb::flow::interface11::graph_iterator< graph, tbb::flow::interface11::graph_node > iterator
static void enqueue(task &t)
Enqueue task for starvation-resistant execution.
Base class for types that should not be copied or assigned.
priority_task_selector(graph_task_priority_queue_t &priority_queue)
bool operator()(const graph_task *left, const graph_task *right)
tbb::task_arena * my_task_arena
void push(const_reference elem)
Pushes elem onto the queue, increasing capacity of queue if necessary.
void wait_for_all()
Wait for reference count to become one, and set reference count to zero.
static tbb::task *const SUCCESSFULLY_ENQUEUED
tbb::task * root_task()
Returns the root task of the graph.
void make_critical(task &t)
graph_iterator & operator=(const graph_iterator &other)
Assignment.
internal::allocate_continuation_proxy & allocate_continuation()
Returns proxy for overloaded new that allocates a continuation task of *this.
wait_functor(tbb::task *t)
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name
A lock that occupies a single byte.
void run(Body body)
Spawns a task that runs a function object.
task_list_type my_reset_task_list
tbb::flow::interface11::graph_iterator< const graph, const tbb::flow::interface11::graph_node > const_iterator
graph_iterator()
Default constructor.
task * execute() __TBB_override
Should be overridden by derived classes.
graph_task(node_priority_t node_priority=no_priority)
tbb::task & prioritize_task(tbb::flow::interface10::graph &g, tbb::task &arena_task)
spawn_functor(tbb::task &t)
bool operator==(const graph_iterator &other) const
Equality.
#define __TBB_ASSERT_EX(predicate, comment)
"Extended" version is useful to suppress warnings if a variable is only used with an assert ...
Tag class used to indicate the "attaching" constructor.
void increment_wait_count()
Base class for tasks generated by graph nodes.
The base of all graph nodes.
void deactivate_graph(tbb::flow::interface10::graph &g)
unsigned int node_priority_t
void activate_graph(tbb::flow::interface10::graph &g)
graph_iterator & operator++()
Pre-increment.
void enqueue_in_graph_arena(tbb::flow::interface10::graph &g, tbb::task &arena_task)
Enqueues a task inside graph arena.
graph_iterator operator++(int)
Post-increment.
GraphContainerType * my_graph
Pure virtual template classes that define interfaces for async communication.
run_task(Body &body, tbb::flow::interface11::node_priority_t node_priority=tbb::flow::interface11::no_priority)
tbb::spin_mutex nodelist_mutex
tbb::flow::interface11::internal::graph_task_priority_queue_t my_priority_queue
run_and_put_task(Receiver &r, Body &body)
#define __TBB_PREVIEW_FLOW_GRAPH_PRIORITIES
Used to form groups of tasks.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
const GraphNodeType & const_reference
GraphNodeType & reference
tbb::concurrent_priority_queue< graph_task *, graph_task_comparator > graph_task_priority_queue_t
A functor that spawns a task.
graph_iterator(const graph_iterator &other)
Copy constructor.
std::list< tbb::task * > task_list_type
Base class for user-defined tasks.
tbb::flow::interface11::graph_node * my_nodes_last
std::forward_iterator_tag iterator_category
internal::return_type_or_void< F >::type execute(F &f)
bool is_cancelled()
return status of graph execution
Concurrent priority queue.
tbb::task * execute() __TBB_override
Should be overridden by derived classes.
void spawn_in_graph_arena(tbb::flow::interface10::graph &g, tbb::task &arena_task)
Spawns a task inside graph arena.
virtual task * execute()=0
Should be overridden by derived classes.