17 #ifndef __TBB_task_arena_H 18 #define __TBB_task_arena_H 20 #define __TBB_task_arena_H_include_area 26 #if __TBB_NUMA_SUPPORT 29 #if TBB_USE_THREADING_TOOLS 36 namespace this_task_arena {
49 namespace interface7 {
58 virtual void operator()()
const = 0;
66 #if __TBB_CPP11_DECLTYPE_PRESENT && !__TBB_CPP11_DECLTYPE_OF_FUNCTION_RETURN_TYPE_BROKEN 67 typedef decltype(declval<F>()())
type;
73 template<
typename F,
typename R>
79 new (my_return_storage.begin()) R(my_func());
88 my_return_storage.begin()->~R();
106 #if __TBB_NUMA_SUPPORT 110 constraints(numa_node_id
id = automatic,
int maximal_concurrency = automatic)
114 numa_node_id numa_id;
122 #if __TBB_TASK_GROUP_CONTEXT 138 #if __TBB_NUMA_SUPPORT 139 numa_node_id my_numa_id;
147 numa_node_id numa_id() {
148 return (my_version_and_traits & numa_support_flag) == numa_support_flag ? my_numa_id : automatic;
154 #if __TBB_TASK_GROUP_CONTEXT 158 #
if __TBB_NUMA_SUPPORT
159 , numa_support_flag = 1
168 , my_max_concurrency(max_concurrency)
169 , my_master_slots(reserved_for_masters)
170 #if __TBB_NUMA_SUPPORT
171 , my_version_and_traits(default_flags | numa_support_flag)
173 , my_version_and_traits(default_flags)
175 , my_initialized(false)
176 #if __TBB_NUMA_SUPPORT
177 , my_numa_id(automatic)
181 #if __TBB_NUMA_SUPPORT 182 task_arena_base(
const constraints& constraints_,
unsigned reserved_for_masters)
184 #if __TBB_TASK_GROUP_CONTEXT 187 , my_max_concurrency(constraints_.max_concurrency)
188 , my_master_slots(reserved_for_masters)
189 , my_version_and_traits(default_flags | numa_support_flag)
190 , my_initialized(
false)
191 , my_numa_id(constraints_.numa_id )
205 static const int automatic = -1;
206 static const int not_initialized = -2;
210 #if __TBB_TASK_ISOLATION 213 template<
typename R,
typename F>
237 __TBB_ASSERT( my_arena,
"task_arena initialization is incomplete" );
238 #if __TBB_TASK_GROUP_CONTEXT 239 __TBB_ASSERT( my_context,
"task_arena initialization is incomplete" );
241 #if TBB_USE_THREADING_TOOLS 246 my_initialized =
true;
256 #if !__TBB_TASK_PRIORITY 260 #if __TBB_TASK_GROUP_CONTEXT 267 template<
typename R,
typename F>
282 task_arena(
int max_concurrency_ = automatic,
unsigned reserved_for_masters = 1)
286 #if __TBB_NUMA_SUPPORT 287 task_arena(
const constraints& constraints_,
unsigned reserved_for_masters = 1)
306 if( my_arena ) my_initialized =
true;
311 if( !my_initialized ) {
312 internal_initialize();
318 inline void initialize(
int max_concurrency_,
unsigned reserved_for_masters = 1) {
320 __TBB_ASSERT(!my_arena,
"Impossible to modify settings of an already initialized task_arena");
321 if( !my_initialized ) {
322 my_max_concurrency = max_concurrency_;
323 my_master_slots = reserved_for_masters;
328 #if __TBB_NUMA_SUPPORT 329 inline void initialize(constraints constraints_,
unsigned reserved_for_masters = 1) {
331 __TBB_ASSERT(!my_arena,
"Impossible to modify settings of an already initialized task_arena");
332 if( !my_initialized ) {
333 my_numa_id = constraints_.numa_id;
334 my_max_concurrency = constraints_.max_concurrency;
335 my_master_slots = reserved_for_masters;
344 __TBB_ASSERT(!my_arena,
"Impossible to modify settings of an already initialized task_arena");
345 if( !my_initialized ) {
347 if ( !my_arena ) internal_initialize();
355 if( my_initialized ) {
356 internal_terminate();
357 my_initialized =
false;
374 #if __TBB_CPP11_RVALUE_REF_PRESENT 377 enqueue_impl(std::forward<F>(f));
381 void enqueue(
const F& f ) {
386 #if __TBB_TASK_PRIORITY 390 #if __TBB_CPP11_RVALUE_REF_PRESENT 392 #if __TBB_PREVIEW_CRITICAL_TASKS 398 enqueue_impl(std::forward<F>(f), p);
402 #if __TBB_PREVIEW_CRITICAL_TASKS 411 #endif// __TBB_TASK_PRIORITY 431 #if __TBB_EXTRA_DEBUG 432 void debug_wait_until_empty() {
439 #endif //__TBB_EXTRA_DEBUG 444 return internal_current_slot();
450 return (my_max_concurrency>1) ? my_max_concurrency : internal_max_concurrency(
this);
454 namespace this_task_arena {
455 #if __TBB_TASK_ISOLATION 475 namespace this_task_arena {
476 using namespace interface7::this_task_arena;
491 #if __TBB_TASK_PRIORITY 504 #undef __TBB_task_arena_H_include_area Base class for types that should not be assigned.
#define __TBB_TASK_GROUP_CONTEXT
atomic< T > & as_atomic(T &t)
static const int not_initialized
task_arena(int max_concurrency_=automatic, unsigned reserved_for_masters=1)
Creates task_arena with certain concurrency limits.
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 ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
static void enqueue(task &t)
Enqueue task for starvation-resistant execution.
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments...
Identifiers declared inside namespace internal should never be used directly by client code...
tbb::aligned_space< R > my_return_storage
static const int priority_critical
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 operator()() const __TBB_override
int max_concurrency() const
Returns the maximal number of threads that can work inside the arena.
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
void move(tbb_thread &t1, tbb_thread &t2)
task_arena(attach)
Creates an instance of task_arena attached to the current arena of the thread.
void consume_result() const
void initialize(attach)
Attaches this instance to the current arena of the thread.
void const char const char int ITT_FORMAT __itt_group_sync s
#define __TBB_EXPORTED_FUNC
void initialize(int max_concurrency_, unsigned reserved_for_masters=1)
Overrides concurrency level and forces initialization of internal representation. ...
__TBB_DEPRECATED void enqueue(F &&f, priority_t p)
#define __TBB_TASK_PRIORITY
Tag class used to indicate the "attaching" constructor.
task_arena(const task_arena &s)
Copies settings from another task_arena.
internal::arena * my_arena
NULL if not currently initialized.
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
internal::return_type_or_void< F >::type execute(const F &f)
unsigned my_master_slots
Reserved master slots.
int max_concurrency()
Returns the maximal number of threads that can work inside the arena.
void __TBB_EXPORTED_FUNC isolate_within_arena(delegate_base &d, intptr_t isolation=0)
intptr_t my_version_and_traits
Special settings.
#define __TBB_EXPORTED_METHOD
#define __TBB_FORWARDING_REF(A)
int my_max_concurrency
Concurrency level for deferred initialization.
internal::return_type_or_void< F >::type isolate(const F &f)
Used to form groups of tasks.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
int current_thread_index()
Returns the index, aka slot number, of the calling thread in its current arena.
void operator()() const __TBB_override
void const char const char int ITT_FORMAT __itt_group_sync p
void __TBB_EXPORTED_METHOD internal_enqueue(task &, intptr_t) const
Base class for user-defined tasks.
internal::return_type_or_void< F >::type execute(F &f)
static int __TBB_EXPORTED_FUNC internal_max_concurrency(const task_arena *)
void enqueue_impl(__TBB_FORWARDING_REF(F) f, priority_t p=priority_t(0))
static int current_thread_index()