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 >
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
 
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::arena * my_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 173 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 223 of file task_arena.h.

224  : task_arena_base(max_concurrency_, reserved_for_masters)
225  , my_initialized(false)
226  {}
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Definition: task_arena.h:130

◆ task_arena() [2/3]

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

Copies settings from another task_arena.

Definition at line 229 of file task_arena.h.

230  : task_arena_base(s.my_max_concurrency, s.my_master_slots)
231  , my_initialized(false)
232  {}
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Definition: task_arena.h:130
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 238 of file task_arena.h.

239  : task_arena_base(automatic, 1) // use default settings if attach fails
240  , my_initialized(false)
241  {
242  internal_attach();
243  if( my_arena ) my_initialized = true;
244  }
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Definition: task_arena.h:130
static const int automatic
Typedef for number of threads that is automatic.
Definition: task_arena.h:150
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106
void __TBB_EXPORTED_METHOD internal_attach()
Definition: arena.cpp:780

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

287  {
288  terminate();
289  }

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

367  {
368  return internal_current_slot();
369  }
static int __TBB_EXPORTED_FUNC internal_current_slot()
Definition: arena.cpp:1015

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

300  {
301  enqueue_impl(std::forward<F>(f));
302  }
void enqueue_impl(__TBB_FORWARDING_REF(F) f, priority_t p=priority_t(0))
Definition: task_arena.h:192

◆ enqueue() [2/2]

template<typename F >
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 315 of file task_arena.h.

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

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

196  {
197 #if !__TBB_TASK_PRIORITY
198  intptr_t p = 0;
199 #endif
200  initialize();
201 #if __TBB_TASK_GROUP_CONTEXT
202  internal_enqueue(*new(task::allocate_root(*my_context)) internal::function_task< typename internal::strip<F>::type >(internal::forward<F>(f)), p);
203 #else
204  internal_enqueue(*new(task::allocate_root()) internal::function_task< typename internal::strip<F>::type >(internal::forward<F>(f)), p);
205 #endif /* __TBB_TASK_GROUP_CONTEXT */
206  }
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
void const char const char int ITT_FORMAT __itt_group_sync p
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:636
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments.
Definition: task_arena.h:247
void __TBB_EXPORTED_METHOD internal_enqueue(task &, intptr_t) const
Definition: arena.cpp:801

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

342  {
344  }
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

References type.

Referenced by tbb::flow::interface10::internal::execute_in_graph_arena(), tbb::flow::interface10::graph::run(), 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 351 of file task_arena.h.

351  {
353  }
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

References type.

◆ execute_impl()

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

Definition at line 209 of file task_arena.h.

209  {
210  initialize();
211  internal::delegated_function<F, R> d(f);
213  return d.consume_result();
214  }
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:862
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments.
Definition: task_arena.h:247

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

247  {
248  if( !my_initialized ) {
251  }
252  }
void __TBB_EXPORTED_METHOD internal_initialize()
Definition: arena.cpp:736

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

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

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

266  {
267  // TODO: decide if this call must be thread-safe
268  __TBB_ASSERT(!my_arena, "Impossible to modify settings of an already initialized task_arena");
269  if( !my_initialized ) {
270  internal_attach();
271  if ( !my_arena ) internal_initialize();
273  }
274  }
void __TBB_EXPORTED_METHOD internal_initialize()
Definition: arena.cpp:736
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106
void __TBB_EXPORTED_METHOD internal_attach()
Definition: arena.cpp:780

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

293 { return my_initialized; }

Referenced by tbb::flow::interface10::internal::execute_in_graph_arena(), and tbb::flow::interface10::graph::prepare_task_arena().

Here is the caller graph for this function:

◆ mark_initialized()

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

Definition at line 177 of file task_arena.h.

177  {
178  __TBB_ASSERT( my_arena, "task_arena initialization is incomplete" );
179 #if __TBB_TASK_GROUP_CONTEXT
180  __TBB_ASSERT( my_context, "task_arena initialization is incomplete" );
181 #endif
182 #if TBB_USE_THREADING_TOOLS
183  // Actual synchronization happens in internal_initialize & internal_attach.
184  // The race on setting my_initialized is benign, but should be hidden from Intel(R) Inspector
185  internal::as_atomic(my_initialized).fetch_and_store<release>(true);
186 #else
187  my_initialized = true;
188 #endif
189  }
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106
Release.
Definition: atomic.h:49
atomic< T > & as_atomic(T &t)
Definition: atomic.h:547

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

372  {
373  // Handle special cases inside the library
375  }
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:114
static int __TBB_EXPORTED_FUNC internal_max_concurrency(const task_arena *)
Definition: arena.cpp:1046

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

278  {
279  if( my_initialized ) {
281  my_initialized = false;
282  }
283  }
void __TBB_EXPORTED_METHOD internal_terminate()
Definition: arena.cpp:769

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

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ tbb::internal::task_scheduler_observer_v3

Definition at line 174 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 176 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.