17 #ifndef __TBB_task_arena_H 18 #define __TBB_task_arena_H 23 #if TBB_USE_THREADING_TOOLS 30 namespace this_task_arena {
43 namespace interface7 {
52 virtual void operator()()
const = 0;
60 #if __TBB_CPP11_DECLTYPE_PRESENT && !__TBB_CPP11_DECLTYPE_OF_FUNCTION_RETURN_TYPE_BROKEN 61 typedef decltype(declval<F>()())
type;
67 template<
typename F,
typename R>
73 new (my_return_storage.
begin()) R(my_func());
82 my_return_storage.
begin()->~R();
104 #if __TBB_TASK_GROUP_CONTEXT 120 #if __TBB_TASK_GROUP_CONTEXT 132 , my_master_slots(reserved_for_masters)
133 , my_version_and_traits(default_flags)
146 static const int automatic = -1;
147 static const int not_initialized = -2;
151 #if __TBB_TASK_ISOLATION 154 template<
typename R,
typename F>
158 return d.consume_result();
179 __TBB_ASSERT( my_arena,
"task_arena initialization is incomplete" );
180 #if __TBB_TASK_GROUP_CONTEXT 181 __TBB_ASSERT( my_context,
"task_arena initialization is incomplete" );
183 #if TBB_USE_THREADING_TOOLS 188 my_initialized =
true;
198 #if !__TBB_TASK_PRIORITY 202 #if __TBB_TASK_GROUP_CONTEXT 209 template<
typename R,
typename F>
212 internal::delegated_function<F, R>
d(f);
214 return d.consume_result();
224 task_arena(
int max_concurrency_ = automatic,
unsigned reserved_for_masters = 1)
226 , my_initialized(false)
232 , my_initialized(false)
241 , my_initialized(false)
244 if( my_arena ) my_initialized =
true;
249 if( !my_initialized ) {
250 internal_initialize();
256 inline void initialize(
int max_concurrency_,
unsigned reserved_for_masters = 1) {
258 __TBB_ASSERT(!my_arena,
"Impossible to modify settings of an already initialized task_arena");
259 if( !my_initialized ) {
260 my_max_concurrency = max_concurrency_;
261 my_master_slots = reserved_for_masters;
269 __TBB_ASSERT(!my_arena,
"Impossible to modify settings of an already initialized task_arena");
270 if( !my_initialized ) {
272 if ( !my_arena ) internal_initialize();
280 if( my_initialized ) {
281 internal_terminate();
282 my_initialized =
false;
299 #if __TBB_CPP11_RVALUE_REF_PRESENT 302 enqueue_impl(std::forward<F>(f));
306 void enqueue(
const F& f ) {
311 #if __TBB_TASK_PRIORITY 315 #if __TBB_CPP11_RVALUE_REF_PRESENT 317 #if __TBB_PREVIEW_CRITICAL_TASKS 323 enqueue_impl(std::forward<F>(f),
p);
327 #if __TBB_PREVIEW_CRITICAL_TASKS 336 #endif// __TBB_TASK_PRIORITY 356 #if __TBB_EXTRA_DEBUG 357 void debug_wait_until_empty() {
364 #endif //__TBB_EXTRA_DEBUG 369 return internal_current_slot();
375 return (my_max_concurrency>1) ? my_max_concurrency : internal_max_concurrency(
this);
379 #if __TBB_TASK_ISOLATION 380 namespace this_task_arena {
398 using interface7::task_arena;
399 #if __TBB_TASK_ISOLATION 400 namespace this_task_arena {
401 using namespace interface7::this_task_arena;
405 namespace this_task_arena {
424 #if !__TBB_TASK_PRIORITY 429 arena.internal_enqueue(t,
p);
task_arena(attach)
Creates an instance of task_arena attached to the current arena of the thread.
void enqueue_impl(__TBB_FORWARDING_REF(F) f, priority_t p=priority_t(0))
void initialize(int max_concurrency_, unsigned reserved_for_masters=1)
Overrides concurrency level and forces initialization of internal representation.
int max_concurrency() const
Returns the maximal number of threads that can work inside the arena.
intptr_t my_version_and_traits
Special settings.
static const int not_initialized
int my_max_concurrency
Concurrency level for deferred initialization.
void consume_result() const
#define __TBB_EXPORTED_FUNC
void move(tbb_thread &t1, tbb_thread &t2)
void const char const char int ITT_FORMAT __itt_group_sync s
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Used to form groups of tasks.
task_arena(int max_concurrency_=automatic, unsigned reserved_for_masters=1)
Creates task_arena with certain concurrency limits.
unsigned my_master_slots
Reserved master slots.
#define __TBB_TASK_PRIORITY
#define __TBB_EXPORTED_METHOD
#define __TBB_FORWARDING_REF(A)
tbb::aligned_space< R > my_return_storage
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
internal::return_type_or_void< F >::type execute(const F &f)
decltype(declval< F >()()) typedef type
Base class for user-defined tasks.
void initialize(attach)
Attaches this instance to the current arena of the thread.
Base class for types that should not be assigned.
static int __TBB_EXPORTED_FUNC internal_max_concurrency(const task_arena *)
task_arena(const task_arena &s)
Copies settings from another task_arena.
static const int priority_critical
Tag class used to indicate the "attaching" constructor.
int current_thread_index()
Returns the index, aka slot number, of the calling thread in its current arena.
static void enqueue(task &t)
Enqueue task for starvation-resistant execution.
void __TBB_EXPORTED_FUNC isolate_within_arena(delegate_base &d, intptr_t reserved=0)
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
atomic< T > & as_atomic(T &t)
void operator()() const __TBB_override
T * begin() const
Pointer to beginning of array.
internal::arena * my_arena
NULL if not currently initialized.
static int current_thread_index()
void operator()() const __TBB_override
void const char const char int ITT_FORMAT __itt_group_sync p
internal::return_type_or_void< F >::type isolate(const F &f)
int max_concurrency()
Returns the maximal number of threads that can work inside the arena.
#define __TBB_TASK_GROUP_CONTEXT
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
internal::return_type_or_void< F >::type execute(F &f)
void enqueue(F &&f, priority_t p)
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
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.