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)
 

Private Attributes

bool my_initialized
 

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...
 

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 172 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 227 of file task_arena.h.

228  : task_arena_base(max_concurrency_, reserved_for_masters)
229  , my_initialized(false)
230  {}
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Definition: task_arena.h:129

◆ task_arena() [2/3]

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

Copies settings from another task_arena.

Definition at line 233 of file task_arena.h.

234  : task_arena_base(s.my_max_concurrency, s.my_master_slots)
235  , my_initialized(false)
236  {}
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Definition: task_arena.h:129
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 242 of file task_arena.h.

243  : task_arena_base(automatic, 1) // use default settings if attach fails
244  , my_initialized(false)
245  {
246  internal_attach();
247  if( my_arena ) my_initialized = true;
248  }
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Definition: task_arena.h:129
void __TBB_EXPORTED_METHOD internal_attach()
Definition: arena.cpp:856
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:105
static const int automatic
Typedef for number of threads that is automatic.
Definition: task_arena.h:149

◆ ~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 291 of file task_arena.h.

291  {
292  terminate();
293  }

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 371 of file task_arena.h.

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

371  {
372  return internal_current_slot();
373  }
static int __TBB_EXPORTED_FUNC internal_current_slot()
Definition: arena.cpp:1103
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 304 of file task_arena.h.

304  {
305  enqueue_impl(std::forward<F>(f));
306  }
void enqueue_impl(__TBB_FORWARDING_REF(F) f, priority_t p=priority_t(0))
Definition: task_arena.h:196

◆ 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 319 of file task_arena.h.

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

319  {
320 #if __TBB_PREVIEW_CRITICAL_TASKS
322  || p == internal::priority_critical, "Invalid priority level value");
323 #else
324  __TBB_ASSERT(p == priority_low || p == priority_normal || p == priority_high, "Invalid priority level value");
325 #endif
326  enqueue_impl(std::forward<F>(f), p);
327  }
void enqueue_impl(__TBB_FORWARDING_REF(F) f, priority_t p=priority_t(0))
Definition: task_arena.h:196
static const int priority_critical
Definition: task.h:302
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
void const char const char int ITT_FORMAT __itt_group_sync p

◆ 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 196 of file task_arena.h.

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

200  {
201 #if !__TBB_TASK_PRIORITY
202  intptr_t p = 0;
203 #endif
204  initialize();
205 #if __TBB_TASK_GROUP_CONTEXT
206  internal_enqueue(*new(task::allocate_root(*my_context)) internal::function_task< typename internal::strip<F>::type >(internal::forward<F>(f)), p);
207 #else
208  internal_enqueue(*new(task::allocate_root()) internal::function_task< typename internal::strip<F>::type >(internal::forward<F>(f)), p);
209 #endif /* __TBB_TASK_GROUP_CONTEXT */
210  }
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:652
task_group_context * my_context
default context of the arena
Definition: task_arena.h:109
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments...
Definition: task_arena.h:251
void __TBB_EXPORTED_METHOD internal_enqueue(task &, intptr_t) const
Definition: arena.cpp:877
void const char const char int ITT_FORMAT __itt_group_sync 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 346 of file task_arena.h.

References type.

Referenced by tbb::flow::interface11::internal::spawn_in_graph_arena().

346  {
348  }
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
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 355 of file task_arena.h.

References type.

355  {
357  }
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

◆ execute_impl()

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

Definition at line 213 of file task_arena.h.

References tbb::interface7::internal::delegated_function< F, R >::consume_result(), and d.

213  {
214  initialize();
215  internal::delegated_function<F, R> d(f);
217  return d.consume_result();
218  }
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments...
Definition: task_arena.h:251
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
Definition: arena.cpp:950
Here is the call graph for this function:

◆ 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 251 of file task_arena.h.

Referenced by tbb::task::enqueue().

251  {
252  if( !my_initialized ) {
255  }
256  }
void __TBB_EXPORTED_METHOD internal_initialize()
Definition: arena.cpp:812
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 259 of file task_arena.h.

References __TBB_ASSERT.

259  {
260  // TODO: decide if this call must be thread-safe
261  __TBB_ASSERT(!my_arena, "Impossible to modify settings of an already initialized task_arena");
262  if( !my_initialized ) {
263  my_max_concurrency = max_concurrency_;
264  my_master_slots = reserved_for_masters;
265  initialize();
266  }
267  }
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:105
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:113
unsigned my_master_slots
Reserved master slots.
Definition: task_arena.h:116
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments...
Definition: task_arena.h:251
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

◆ initialize() [3/3]

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

Attaches this instance to the current arena of the thread.

Definition at line 270 of file task_arena.h.

References __TBB_ASSERT.

270  {
271  // TODO: decide if this call must be thread-safe
272  __TBB_ASSERT(!my_arena, "Impossible to modify settings of an already initialized task_arena");
273  if( !my_initialized ) {
274  internal_attach();
275  if ( !my_arena ) internal_initialize();
277  }
278  }
void __TBB_EXPORTED_METHOD internal_attach()
Definition: arena.cpp:856
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:105
void __TBB_EXPORTED_METHOD internal_initialize()
Definition: arena.cpp:812
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

◆ 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 297 of file task_arena.h.

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

297 { return my_initialized; }
Here is the caller graph for this function:

◆ mark_initialized()

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

Definition at line 181 of file task_arena.h.

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

181  {
182  __TBB_ASSERT( my_arena, "task_arena initialization is incomplete" );
183 #if __TBB_TASK_GROUP_CONTEXT
184  __TBB_ASSERT( my_context, "task_arena initialization is incomplete" );
185 #endif
186 #if TBB_USE_THREADING_TOOLS
187  // Actual synchronization happens in internal_initialize & internal_attach.
188  // The race on setting my_initialized is benign, but should be hidden from Intel(R) Inspector
189  internal::as_atomic(my_initialized).fetch_and_store<release>(true);
190 #else
191  my_initialized = true;
192 #endif
193  }
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:105
task_group_context * my_context
default context of the arena
Definition: task_arena.h:109
atomic< T > & as_atomic(T &t)
Definition: atomic.h:572
Release.
Definition: atomic.h:59
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
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 376 of file task_arena.h.

376  {
377  // Handle special cases inside the library
379  }
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:113
static int __TBB_EXPORTED_FUNC internal_max_concurrency(const task_arena *)
Definition: arena.cpp:1133

◆ 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 282 of file task_arena.h.

282  {
283  if( my_initialized ) {
285  my_initialized = false;
286  }
287  }
void __TBB_EXPORTED_METHOD internal_terminate()
Definition: arena.cpp:845

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 173 of file task_arena.h.

◆ tbb::this_task_arena::max_concurrency

Member Data Documentation

◆ my_initialized

bool tbb::interface7::task_arena::my_initialized
private

Definition at line 180 of file task_arena.h.


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

Copyright © 2005-2019 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.