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
 
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::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 169 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 224 of file task_arena.h.

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

◆ task_arena() [2/3]

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

Copies settings from another task_arena.

Definition at line 230 of file task_arena.h.

231  : task_arena_base(s.my_max_concurrency, s.my_master_slots)
232  , my_initialized(false)
233  {}
void const char const char int ITT_FORMAT __itt_group_sync s
task_arena_base(int max_concurrency, unsigned reserved_for_masters)
Definition: task_arena.h:126

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

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

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

288  {
289  terminate();
290  }

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

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

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

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

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

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

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

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

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

343  {
345  }
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 352 of file task_arena.h.

352  {
354  }
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 210 of file task_arena.h.

210  {
211  initialize();
212  internal::delegated_function<F, R> d(f);
214  return d.consume_result();
215  }
void __TBB_EXPORTED_METHOD internal_execute(delegate_base &) const
Definition: arena.cpp:858
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 initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments.
Definition: task_arena.h:248

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

248  {
249  if( !my_initialized ) {
252  }
253  }
void __TBB_EXPORTED_METHOD internal_initialize()
Definition: arena.cpp:732

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

256  {
257  // TODO: decide if this call must be thread-safe
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;
262  initialize();
263  }
264  }
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:110
unsigned my_master_slots
Reserved master slots.
Definition: task_arena.h:113
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:102
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments.
Definition: task_arena.h:248

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

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

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

294 { 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 178 of file task_arena.h.

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

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

373  {
374  // Handle special cases inside the library
376  }
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:110
static int __TBB_EXPORTED_FUNC internal_max_concurrency(const task_arena *)
Definition: arena.cpp:1042

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

279  {
280  if( my_initialized ) {
282  my_initialized = false;
283  }
284  }
void __TBB_EXPORTED_METHOD internal_terminate()
Definition: arena.cpp:765

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