21 #ifndef __TBB_task_group_H 22 #define __TBB_task_group_H 25 #include "tbb_exception.h" 27 #if __TBB_TASK_GROUP_CONTEXT 44 static const intptr_t scheduled = 0x1;
49 void mark_scheduled () {
51 if ( my_state & scheduled )
52 internal::throw_exception( internal::eid_invalid_multiple_scheduling );
53 my_state |= scheduled;
56 task_handle(
const F& f ) : my_func(f), my_state(0) {}
58 void operator() ()
const { my_func(); }
61 enum task_group_status {
70 class task_handle_task :
public task {
77 task_handle_task(
task_handle<F>& h ) : my_handle(h) { h.mark_scheduled(); }
83 task_group_context my_context;
85 task& owner () {
return *my_root; }
88 task_group_status internal_run_and_wait( F& f ) {
90 if ( !my_context.is_group_execution_cancelled() )
92 } __TBB_CATCH( ... ) {
93 my_context.register_pending_exception();
98 template<
typename F,
typename Task>
99 void internal_run( F& f ) {
100 owner().spawn( *
new( owner().allocate_additional_child_of(*my_root) ) Task(f) );
105 : my_context(task_group_context::bound, task_group_context::default_traits | traits)
107 my_root =
new( task::allocate_root(my_context) ) empty_task;
108 my_root->set_ref_count(1);
112 if( my_root->ref_count() > 1 ) {
113 bool stack_unwinding_in_progress = std::uncaught_exception();
116 if ( !is_canceling() )
119 my_root->wait_for_all();
120 } __TBB_CATCH (...) {
121 task::destroy(*my_root);
124 task::destroy(*my_root);
125 if ( !stack_unwinding_in_progress )
126 internal::throw_exception( internal::eid_missing_wait );
129 task::destroy(*my_root);
138 task_group_status wait() {
140 my_root->wait_for_all();
141 } __TBB_CATCH( ... ) {
145 if ( my_context.is_group_execution_cancelled() ) {
153 bool is_canceling() {
154 return my_context.is_group_execution_cancelled();
158 my_context.cancel_group_execution();
166 task_group () : task_group_base( task_group_context::concurrent_wait ) {}
174 using task_group_base::run;
178 void run(
const F& f ) {
179 internal_run< const F, internal::function_task<F> >( f );
183 task_group_status run_and_wait(
const F& f ) {
184 return internal_run_and_wait<const F>( f );
190 return internal_run_and_wait< task_handle<F> >( h );
199 return internal_run_and_wait< task_handle<F> >( h );
202 task_group_status wait() {
203 task_group_status res = task_group_base::wait();
204 my_root->set_ref_count(1);
210 bool is_current_task_group_canceling() {
211 return task::self().is_cancelled();
Definition: task_group.h:194
Definition: task_group.h:164
Definition: task_group.h:80
Definition: task_group.h:32
Definition: task_group.h:39
Definition: _flow_graph_async_msg_impl.h:32
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44