Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::interface7::task_arena Class Reference

#include <task_arena.h>

Inheritance diagram for tbb::interface7::task_arena:
Collaboration diagram for tbb::interface7::task_arena:

Classes

struct  attach
 Tag class used to indicate the "attaching" constructor. More...
 

Public Member Functions

 task_arena (int max_concurrency_=automatic, unsigned reserved_for_masters=1)
 Creates task_arena with certain concurrency limits. More...
 
 task_arena (const task_arena &s)
 Copies settings from another task_arena. More...
 
 task_arena (attach)
 Creates an instance of task_arena attached to the current arena of the thread. More...
 
void initialize ()
 Forces allocation of the resources for the task_arena as specified in constructor arguments. More...
 
void initialize (int max_concurrency_, unsigned reserved_for_masters=1)
 Overrides concurrency level and forces initialization of internal representation. More...
 
void initialize (attach)
 Attaches this instance to the current arena of the thread. More...
 
void terminate ()
 
 ~task_arena ()
 
bool is_active () const
 
template<typename F >
void enqueue (F &&f)
 
template<typename F >
__TBB_DEPRECATED void enqueue (F &&f, priority_t p)
 
template<typename F >
internal::return_type_or_void< F >::type execute (F &f)
 
template<typename F >
internal::return_type_or_void< F >::type execute (const F &f)
 
int max_concurrency () const
 Returns the maximal number of threads that can work inside the arena. More...
 

Static Public Member Functions

static int current_thread_index ()
 

Private Member Functions

void mark_initialized ()
 
template<typename F >
void enqueue_impl (__TBB_FORWARDING_REF(F) f, priority_t p=priority_t(0))
 
template<typename R , typename F >
execute_impl (F &f)
 

Friends

class tbb::internal::task_scheduler_observer_v3
 
void task::enqueue (task &, task_arena &, priority_t)
 
int tbb::this_task_arena::max_concurrency ()
 

Additional Inherited Members

- Static Public Attributes inherited from tbb::interface7::internal::task_arena_base
static const int automatic = -1
 Typedef for number of threads that is automatic. More...
 
static const int not_initialized = -2
 
- Protected Types inherited from tbb::interface7::internal::task_arena_base
enum  { default_flags, exact_exception_flag = task_group_context::exact_exception }
 
- Protected Member Functions inherited from tbb::interface7::internal::task_arena_base
 task_arena_base (int max_concurrency, unsigned reserved_for_masters)
 
void __TBB_EXPORTED_METHOD internal_initialize ()
 
void __TBB_EXPORTED_METHOD internal_terminate ()
 
void __TBB_EXPORTED_METHOD internal_attach ()
 
void __TBB_EXPORTED_METHOD internal_enqueue (task &, intptr_t) const
 
void __TBB_EXPORTED_METHOD internal_execute (delegate_base &) const
 
void __TBB_EXPORTED_METHOD internal_wait () const
 
- Static Protected Member Functions inherited from tbb::interface7::internal::task_arena_base
static int __TBB_EXPORTED_FUNC internal_current_slot ()
 
static int __TBB_EXPORTED_FUNC internal_max_concurrency (const task_arena *)
 
- Protected Attributes inherited from tbb::interface7::internal::task_arena_base
internal::arenamy_arena
 NULL if not currently initialized. More...
 
task_group_contextmy_context
 default context of the arena More...
 
int my_max_concurrency
 Concurrency level for deferred initialization. More...
 
unsigned my_master_slots
 Reserved master slots. More...
 
intptr_t my_version_and_traits
 Special settings. More...
 
bool my_initialized
 

Detailed Description

1-to-1 proxy representation class of scheduler's arena Constructors set up settings only, real construction is deferred till the first method invocation Destructor only removes one of the references to the inner arena representation. Final destruction happens when all the references (and the work) are gone.

Definition at line 228 of file task_arena.h.

Constructor & Destructor Documentation

◆ task_arena() [1/3]

tbb::interface7::task_arena::task_arena ( int  max_concurrency_ = automatic,
unsigned  reserved_for_masters = 1 
)
inline

Creates task_arena with certain concurrency limits.

Sets up settings only, real construction is deferred till the first method invocation

  • max_concurrency specifies total number of slots in arena where threads work
  • reserved_for_masters specifies number of slots to be used by master threads only. Value of 1 is default and reflects behavior of implicit arenas.

Definition at line 282 of file task_arena.h.

283  : task_arena_base(max_concurrency_, reserved_for_masters)
284  {}
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Definition: task_arena.h:163

◆ task_arena() [2/3]

tbb::interface7::task_arena::task_arena ( const task_arena s)
inline

Copies settings from another task_arena.

Definition at line 298 of file task_arena.h.

299  : task_arena_base(s.my_max_concurrency, s.my_master_slots)
300  {}
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Definition: task_arena.h:163
void const char const char int ITT_FORMAT __itt_group_sync s

◆ task_arena() [3/3]

tbb::interface7::task_arena::task_arena ( attach  )
inlineexplicit

Creates an instance of task_arena attached to the current arena of the thread.

Definition at line 307 of file task_arena.h.

308  : task_arena_base(automatic, 1) // use default settings if attach fails
309  {
310  internal_attach();
311  if( my_arena ) my_initialized = true;
312  }
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:120
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Definition: task_arena.h:163
static const int automatic
Typedef for number of threads that is automatic.
Definition: task_arena.h:205
void __TBB_EXPORTED_METHOD internal_attach()

◆ ~task_arena()

tbb::interface7::task_arena::~task_arena ( )
inline

Removes the reference to the internal arena representation, and destroys the external object. Not thread safe wrt concurrent invocations of other methods.

Definition at line 368 of file task_arena.h.

368  {
369  terminate();
370  }

Member Function Documentation

◆ current_thread_index()

static int tbb::interface7::task_arena::current_thread_index ( )
inlinestatic

Returns the index, aka slot number, of the calling thread in its current arena This method is deprecated and replaced with this_task_arena::current_thread_index()

Definition at line 448 of file task_arena.h.

448  {
449  return internal_current_slot();
450  }
static int __TBB_EXPORTED_FUNC internal_current_slot()

Referenced by tbb::this_task_arena::current_thread_index().

Here is the caller graph for this function:

◆ enqueue() [1/2]

template<typename F >
void tbb::interface7::task_arena::enqueue ( F &&  f)
inline

Enqueues a task into the arena to process a functor, and immediately returns. Does not require the calling thread to join the arena

Definition at line 381 of file task_arena.h.

381  {
382  enqueue_impl(std::forward<F>(f));
383  }
void enqueue_impl(__TBB_FORWARDING_REF(F) f, priority_t p=priority_t(0))
Definition: task_arena.h:251

◆ enqueue() [2/2]

template<typename F >
__TBB_DEPRECATED void tbb::interface7::task_arena::enqueue ( F &&  f,
priority_t  p 
)
inline

Enqueues a task with priority p into the arena to process a functor f, and immediately returns. Does not require the calling thread to join the arena

Definition at line 396 of file task_arena.h.

396  {
397 #if __TBB_PREVIEW_CRITICAL_TASKS
399  || p == internal::priority_critical, "Invalid priority level value");
400 #else
401  __TBB_ASSERT(p == priority_low || p == priority_normal || p == priority_high, "Invalid priority level value");
402 #endif
403  enqueue_impl(std::forward<F>(f), p);
404  }
void enqueue_impl(__TBB_FORWARDING_REF(F) f, priority_t p=priority_t(0))
Definition: task_arena.h:251
static const int priority_critical
Definition: task.h:313
void const char const char int ITT_FORMAT __itt_group_sync p
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

References __TBB_ASSERT, p, tbb::internal::priority_critical, tbb::priority_high, tbb::priority_low, and tbb::priority_normal.

◆ enqueue_impl()

template<typename F >
void tbb::interface7::task_arena::enqueue_impl ( __TBB_FORWARDING_REF(F)  f,
priority_t  p = priority_t(0) 
)
inlineprivate

Definition at line 251 of file task_arena.h.

255  {
256 #if !__TBB_TASK_PRIORITY
257  intptr_t p = 0;
258 #endif
259  initialize();
260 #if __TBB_TASK_GROUP_CONTEXT
261  internal_enqueue(*new(task::allocate_root(*my_context)) internal::function_task< typename internal::strip<F>::type >(internal::forward<F>(f)), p);
262 #else
263  internal_enqueue(*new(task::allocate_root()) internal::function_task< typename internal::strip<F>::type >(internal::forward<F>(f)), p);
264 #endif /* __TBB_TASK_GROUP_CONTEXT */
265  }
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments.
Definition: task_arena.h:315
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:663
task_group_context * my_context
default context of the arena
Definition: task_arena.h:124
void const char const char int ITT_FORMAT __itt_group_sync p
void __TBB_EXPORTED_METHOD internal_enqueue(task &, intptr_t) const

References tbb::task::allocate_root(), and p.

Here is the call graph for this function:

◆ execute() [1/2]

template<typename F >
internal::return_type_or_void<F>::type tbb::interface7::task_arena::execute ( F &  f)
inline

Joins the arena and executes a mutable functor, then returns If not possible to join, wraps the functor into a task, enqueues it and waits for task completion Can decrement the arena demand for workers, causing a worker to leave and free a slot to the calling thread Since C++11, the method returns the value returned by functor (prior to C++11 it returns void).

Definition at line 423 of file task_arena.h.

423  {
425  }
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_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type

References type.

Referenced by tbb::flow::interface10::graph::run(), tbb::flow::interface11::internal::spawn_in_graph_arena(), and tbb::flow::interface10::graph::wait_for_all().

Here is the caller graph for this function:

◆ execute() [2/2]

template<typename F >
internal::return_type_or_void<F>::type tbb::interface7::task_arena::execute ( const F &  f)
inline

Joins the arena and executes a constant functor, then returns If not possible to join, wraps the functor into a task, enqueues it and waits for task completion Can decrement the arena demand for workers, causing a worker to leave and free a slot to the calling thread Since C++11, the method returns the value returned by functor (prior to C++11 it returns void).

Definition at line 432 of file task_arena.h.

432  {
434  }
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_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type

References type.

◆ execute_impl()

template<typename R , typename F >
R tbb::interface7::task_arena::execute_impl ( F &  f)
inlineprivate

Definition at line 268 of file task_arena.h.

268  {
269  initialize();
270  internal::delegated_function<F, R> d(f);
272  return d.consume_result();
273  }
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments.
Definition: task_arena.h:315
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 __TBB_EXPORTED_METHOD internal_execute(delegate_base &) const

References d.

◆ initialize() [1/3]

void tbb::interface7::task_arena::initialize ( )
inline

Forces allocation of the resources for the task_arena as specified in constructor arguments.

Definition at line 315 of file task_arena.h.

315  {
316  if( !my_initialized ) {
319  }
320  }
void __TBB_EXPORTED_METHOD internal_initialize()

Referenced by tbb::flow::interface10::graph::prepare_task_arena().

Here is the caller graph for this function:

◆ initialize() [2/3]

void tbb::interface7::task_arena::initialize ( int  max_concurrency_,
unsigned  reserved_for_masters = 1 
)
inline

Overrides concurrency level and forces initialization of internal representation.

Definition at line 323 of file task_arena.h.

323  {
324  // TODO: decide if this call must be thread-safe
325  __TBB_ASSERT(!my_arena, "Impossible to modify settings of an already initialized task_arena");
326  if( !my_initialized ) {
327  my_max_concurrency = max_concurrency_;
328  my_master_slots = reserved_for_masters;
329  initialize();
330  }
331  }
unsigned my_master_slots
Reserved master slots.
Definition: task_arena.h:131
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments.
Definition: task_arena.h:315
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:128
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:120
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

References __TBB_ASSERT.

◆ initialize() [3/3]

void tbb::interface7::task_arena::initialize ( attach  )
inline

Attaches this instance to the current arena of the thread.

Definition at line 347 of file task_arena.h.

347  {
348  // TODO: decide if this call must be thread-safe
349  __TBB_ASSERT(!my_arena, "Impossible to modify settings of an already initialized task_arena");
350  if( !my_initialized ) {
351  internal_attach();
352  if ( !my_arena ) internal_initialize();
354  }
355  }
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:120
void __TBB_EXPORTED_METHOD internal_initialize()
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
void __TBB_EXPORTED_METHOD internal_attach()

References __TBB_ASSERT.

◆ is_active()

bool tbb::interface7::task_arena::is_active ( ) const
inline

Returns true if the arena is active (initialized); false otherwise. The name was chosen to match a task_scheduler_init method with the same semantics.

Definition at line 374 of file task_arena.h.

Referenced by tbb::flow::interface11::internal::enqueue_in_graph_arena(), tbb::flow::interface10::graph::prepare_task_arena(), and tbb::flow::interface11::internal::spawn_in_graph_arena().

Here is the caller graph for this function:

◆ mark_initialized()

void tbb::interface7::task_arena::mark_initialized ( )
inlineprivate

Definition at line 236 of file task_arena.h.

236  {
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" );
240 #endif
241 #if TBB_USE_THREADING_TOOLS
242  // Actual synchronization happens in internal_initialize & internal_attach.
243  // The race on setting my_initialized is benign, but should be hidden from Intel(R) Inspector
244  internal::as_atomic(my_initialized).fetch_and_store<release>(true);
245 #else
246  my_initialized = true;
247 #endif
248  }
Release.
Definition: atomic.h:59
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:120
task_group_context * my_context
default context of the arena
Definition: task_arena.h:124
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
atomic< T > & as_atomic(T &t)
Definition: atomic.h:572

References __TBB_ASSERT, tbb::internal::as_atomic(), and tbb::release.

Here is the call graph for this function:

◆ max_concurrency()

int tbb::interface7::task_arena::max_concurrency ( ) const
inline

Returns the maximal number of threads that can work inside the arena.

Definition at line 453 of file task_arena.h.

453  {
454  // Handle special cases inside the library
456  }
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:128
static int __TBB_EXPORTED_FUNC internal_max_concurrency(const task_arena *)

◆ terminate()

void tbb::interface7::task_arena::terminate ( )
inline

Removes the reference to the internal arena representation. Not thread safe wrt concurrent invocations of other methods.

Definition at line 359 of file task_arena.h.

359  {
360  if( my_initialized ) {
362  my_initialized = false;
363  }
364  }
void __TBB_EXPORTED_METHOD internal_terminate()

Referenced by tbb::flow::interface10::graph::prepare_task_arena().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ task::enqueue

void task::enqueue ( task ,
task_arena ,
priority_t   
)
friend

◆ tbb::internal::task_scheduler_observer_v3

Definition at line 229 of file task_arena.h.

◆ tbb::this_task_arena::max_concurrency


The documentation for this class was generated from the following file:

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.