21 #ifndef __TBB_task_arena_H 22 #define __TBB_task_arena_H 25 #include "tbb_exception.h" 26 #if TBB_USE_THREADING_TOOLS 37 class task_scheduler_observer_v3;
41 namespace interface7 {
46 class delegate_base : no_assign {
48 virtual void operator()()
const = 0;
49 virtual ~delegate_base() {}
53 class delegated_function :
public delegate_base {
55 void operator()()
const {
59 delegated_function ( F& f ) : my_func(f) {}
62 class task_arena_base {
65 internal::arena* my_arena;
67 #if __TBB_TASK_GROUP_CONTEXT 68 task_group_context *my_context;
73 int my_max_concurrency;
76 unsigned my_master_slots;
79 intptr_t my_version_and_traits;
83 #if __TBB_TASK_GROUP_CONTEXT 84 | (task_group_context::default_traits & task_group_context::exact_exception)
85 , exact_exception_flag = task_group_context::exact_exception
89 task_arena_base(
int max_concurrency,
unsigned reserved_for_masters)
91 #if __TBB_TASK_GROUP_CONTEXT
94 , my_max_concurrency(max_concurrency)
95 , my_master_slots(reserved_for_masters)
96 , my_version_and_traits(default_flags)
99 void __TBB_EXPORTED_METHOD internal_initialize();
100 void __TBB_EXPORTED_METHOD internal_terminate();
101 void __TBB_EXPORTED_METHOD internal_attach();
102 void __TBB_EXPORTED_METHOD internal_enqueue( task&, intptr_t )
const;
103 void __TBB_EXPORTED_METHOD internal_execute( delegate_base& )
const;
104 void __TBB_EXPORTED_METHOD internal_wait()
const;
105 static int __TBB_EXPORTED_FUNC internal_current_slot();
108 static const int automatic = -1;
123 void mark_initialized() {
124 __TBB_ASSERT( my_arena,
"task_arena initialization is incomplete" );
125 #if __TBB_TASK_GROUP_CONTEXT 126 __TBB_ASSERT( my_context,
"task_arena initialization is incomplete" );
128 #if TBB_USE_THREADING_TOOLS 131 internal::as_atomic(my_initialized).fetch_and_store<
release>(
true);
133 my_initialized =
true;
144 task_arena(
int max_concurrency = automatic,
unsigned reserved_for_masters = 1)
145 : task_arena_base(max_concurrency, reserved_for_masters)
146 , my_initialized(false)
151 : task_arena_base(s.my_max_concurrency, s.my_master_slots)
152 , my_initialized(false)
160 : task_arena_base(automatic, 1)
161 , my_initialized(false)
164 if( my_arena ) my_initialized =
true;
169 if( !my_initialized ) {
170 internal_initialize();
176 inline void initialize(
int max_concurrency,
unsigned reserved_for_masters = 1) {
178 __TBB_ASSERT( !my_arena,
"Impossible to modify settings of an already initialized task_arena");
179 if( !my_initialized ) {
180 my_max_concurrency = max_concurrency;
181 my_master_slots = reserved_for_masters;
189 __TBB_ASSERT( !my_arena,
"Impossible to modify settings of an already initialized task_arena");
190 if( !my_initialized ) {
192 if( !my_arena ) internal_initialize();
200 if( my_initialized ) {
201 internal_terminate();
202 my_initialized =
false;
221 #if __TBB_TASK_GROUP_CONTEXT 222 internal_enqueue( *
new( task::allocate_root(*my_context) ) internal::function_task<F>(f), 0 );
224 internal_enqueue( *
new( task::allocate_root() ) internal::function_task<F>(f), 0 );
228 #if __TBB_TASK_PRIORITY 233 __TBB_ASSERT( p == priority_low || p == priority_normal || p == priority_high,
"Invalid priority level value" );
235 #if __TBB_TASK_GROUP_CONTEXT 236 internal_enqueue( *
new( task::allocate_root(*my_context) ) internal::function_task<F>(f), (intptr_t)p );
238 internal_enqueue( *
new( task::allocate_root() ) internal::function_task<F>(f), (intptr_t)p );
241 #endif// __TBB_TASK_PRIORITY 249 internal::delegated_function<F> d(f);
250 internal_execute( d );
259 internal::delegated_function<const F> d(f);
260 internal_execute( d );
263 #if __TBB_EXTRA_DEBUG 264 void debug_wait_until_empty() {
271 #endif //__TBB_EXTRA_DEBUG 275 return internal_current_slot();
static int current_thread_index()
Returns the index, aka slot number, of the calling thread in its current arena.
Definition: task_arena.h:274
void enqueue(const F &f)
Enqueues a task into the arena to process a functor, and immediately returns.
Definition: task_arena.h:219
task_arena(int max_concurrency=automatic, unsigned reserved_for_masters=1)
Creates task_arena with certain concurrency limits.
Definition: task_arena.h:144
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments...
Definition: task_arena.h:168
bool is_active() const
Returns true if the arena is active (initialized); false otherwise.
Definition: task_arena.h:214
task_arena(const task_arena &s)
Copies settings from another task_arena.
Definition: task_arena.h:150
task_arena(attach)
Creates an instance of task_arena attached to the current arena of the thread.
Definition: task_arena.h:159
~task_arena()
Removes the reference to the internal arena representation, and destroys the external object...
Definition: task_arena.h:208
*/
Definition: material.h:665
void terminate()
Removes the reference to the internal arena representation.
Definition: task_arena.h:199
Definition: _flow_graph_async_msg_impl.h:32
void execute(F &f)
Joins the arena and executes a functor, then returns If not possible to join, wraps the functor into ...
Definition: task_arena.h:247
Release.
Definition: atomic.h:49
void enqueue(const F &f, priority_t p)
Enqueues a task with priority p into the arena to process a functor f, and immediately returns...
Definition: task_arena.h:232
void initialize(attach)
Attaches this instance to the current arena of the thread.
Definition: task_arena.h:187
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44
1-to-1 proxy representation class of scheduler's arena Constructors set up settings only...
Definition: task_arena.h:120
void execute(const F &f)
Joins the arena and executes a functor, then returns If not possible to join, wraps the functor into ...
Definition: task_arena.h:257
Tag class used to indicate the "attaching" constructor.
Definition: task_arena.h:156
Definition: task_scheduler_observer.h:40
void initialize(int max_concurrency, unsigned reserved_for_masters=1)
Overrides concurrency level and forces initialization of internal representation. ...
Definition: task_arena.h:176