Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::internal::arena Class Reference

#include <arena.h>

Inheritance diagram for tbb::internal::arena:
Collaboration diagram for tbb::internal::arena:

Public Types

enum  new_work_type { work_spawned, wakeup, work_enqueued }
 Types of work advertised by advertise_new_work() More...
 
typedef padded< arena_basebase_type
 
typedef uintptr_t pool_state_t
 

Public Member Functions

 arena (market &, unsigned max_num_workers, unsigned num_reserved_slots)
 Constructor. More...
 
mail_outboxmailbox (affinity_id id)
 Get reference to mailbox corresponding to given affinity_id. More...
 
void free_arena ()
 Completes arena shutdown, destructs and deallocates it. More...
 
unsigned num_workers_active ()
 The number of workers active in the arena. More...
 
template<arena::new_work_type work_type>
void advertise_new_work ()
 If necessary, raise a flag that there is new job in arena. More...
 
bool is_out_of_work ()
 Check if there is job anywhere in arena. More...
 
void enqueue_task (task &, intptr_t, FastRandom &)
 enqueue a task into starvation-resistance queue More...
 
void process (generic_scheduler &)
 Registers the worker with the arena and enters TBB scheduler dispatch loop. More...
 
template<unsigned ref_param>
void on_thread_leaving ()
 Notification that worker or master leaves its arena. More...
 
bool has_enqueued_tasks ()
 Check for the presence of enqueued tasks at all priority levels. More...
 
template<bool as_worker>
size_t occupy_free_slot (generic_scheduler &s)
 Tries to occupy a slot in the arena. On success, returns the slot index; if no slot is available, returns out_of_arena. More...
 
size_t occupy_free_slot_in_range (generic_scheduler &s, size_t lower, size_t upper)
 Tries to occupy a slot in the specified range. More...
 

Static Public Member Functions

static arenaallocate_arena (market &, unsigned num_slots, unsigned num_reserved_slots)
 Allocate an instance of arena. More...
 
static int unsigned num_arena_slots (unsigned num_slots)
 
static int allocation_size (unsigned num_slots)
 
static bool is_busy_or_empty (pool_state_t s)
 No tasks to steal or snapshot is being taken. More...
 

Public Attributes

arena_slot my_slots [1]
 
- Public Attributes inherited from tbb::internal::padded_base< arena_base, NFS_MaxLineSize, sizeof(arena_base) % NFS_MaxLineSize >
char pad [S - R]
 
- Public Attributes inherited from tbb::internal::arena_base
unsigned my_num_workers_allotted
 The number of workers that have been marked out by the resource manager to service the arena. More...
 
atomic< unsigned > my_references
 Reference counter for the arena. More...
 
atomic< unsigned > my_limit
 The maximal number of currently busy slots. More...
 
task_stream< num_priority_levelsmy_task_stream
 Task pool for the tasks scheduled via task::enqueue() method. More...
 
unsigned my_max_num_workers
 The number of workers requested by the master thread owning the arena. More...
 
int my_num_workers_requested
 The number of workers that are currently requested from the resource manager. More...
 
tbb::atomic< uintptr_t > my_pool_state
 Current task pool state and estimate of available tasks amount. More...
 
marketmy_market
 The market that owns this arena. More...
 
uintptr_t my_aba_epoch
 ABA prevention marker. More...
 
cpu_ctl_env my_cpu_ctl_env
 FPU control settings of arena's master thread captured at the moment of arena instantiation. More...
 
unsigned my_num_slots
 The number of slots in the arena. More...
 
unsigned my_num_reserved_slots
 The number of reserved slots (can be occupied only by masters). More...
 
concurrent_monitor my_exit_monitors
 Waiting object for master threads that cannot join the arena. More...
 
- Public Attributes inherited from tbb::internal::padded_base< intrusive_list_node, NFS_MaxLineSize, sizeof(intrusive_list_node) % NFS_MaxLineSize >
char pad [S - R]
 
- Public Attributes inherited from tbb::internal::intrusive_list_node
intrusive_list_nodemy_prev_node
 
intrusive_list_nodemy_next_node
 

Static Public Attributes

static const pool_state_t SNAPSHOT_EMPTY = 0
 No tasks to steal since last snapshot was taken. More...
 
static const pool_state_t SNAPSHOT_FULL = pool_state_t(-1)
 At least one task has been offered for stealing since the last snapshot started. More...
 
static const unsigned ref_external_bits = 12
 The number of least significant bits for external references. More...
 
static const unsigned ref_external = 1
 Reference increment values for externals and workers. More...
 
static const unsigned ref_worker = 1<<ref_external_bits
 
static const size_t out_of_arena = ~size_t(0)
 

Private Member Functions

void restore_priority_if_need ()
 If enqueued tasks found, restore arena priority and task presence status. More...
 

Detailed Description

Definition at line 175 of file arena.h.

Member Typedef Documentation

◆ base_type

Definition at line 180 of file arena.h.

◆ pool_state_t

Definition at line 214 of file arena.h.

Member Enumeration Documentation

◆ new_work_type

Types of work advertised by advertise_new_work()

Enumerator
work_spawned 
wakeup 
work_enqueued 

Definition at line 183 of file arena.h.

Constructor & Destructor Documentation

◆ arena()

tbb::internal::arena::arena ( market m,
unsigned  max_num_workers,
unsigned  num_reserved_slots 
)

Constructor.

Definition at line 186 of file arena.cpp.

186  {
187  __TBB_ASSERT( !my_guard, "improperly allocated arena?" );
188  __TBB_ASSERT( sizeof(my_slots[0]) % NFS_GetLineSize()==0, "arena::slot size not multiple of cache line size" );
189  __TBB_ASSERT( (uintptr_t)this % NFS_GetLineSize()==0, "arena misaligned" );
190 #if __TBB_TASK_PRIORITY
191  __TBB_ASSERT( !my_reload_epoch && !my_orphaned_tasks && !my_skipped_fifo_priority, "New arena object is not zeroed" );
192 #endif /* __TBB_TASK_PRIORITY */
193  my_market = &m;
194  my_limit = 1;
195  // Two slots are mandatory: for the master, and for 1 worker (required to support starvation resistant tasks).
196  my_num_slots = num_arena_slots(num_slots);
197  my_num_reserved_slots = num_reserved_slots;
198  my_max_num_workers = num_slots-num_reserved_slots;
199  my_references = ref_external; // accounts for the master
200 #if __TBB_TASK_PRIORITY
201  my_bottom_priority = my_top_priority = normalized_normal_priority;
202 #endif /* __TBB_TASK_PRIORITY */
203  my_aba_epoch = m.my_arenas_aba_epoch;
204 #if __TBB_ARENA_OBSERVER
205  my_observers.my_arena = this;
206 #endif
208  // Construct slots. Mark internal synchronization elements for the tools.
209  for( unsigned i = 0; i < my_num_slots; ++i ) {
210  __TBB_ASSERT( !my_slots[i].my_scheduler && !my_slots[i].task_pool, NULL );
211  __TBB_ASSERT( !my_slots[i].task_pool_ptr, NULL );
212  __TBB_ASSERT( !my_slots[i].my_task_pool_size, NULL );
213  ITT_SYNC_CREATE(my_slots + i, SyncType_Scheduler, SyncObj_WorkerTaskPool);
214  mailbox(i+1).construct();
215  ITT_SYNC_CREATE(&mailbox(i+1), SyncType_Scheduler, SyncObj_Mailbox);
216  my_slots[i].hint_for_pop = i;
217 #if __TBB_PREVIEW_CRITICAL_TASKS
218  my_slots[i].hint_for_critical = i;
219 #endif
220 #if __TBB_STATISTICS
221  my_slots[i].my_counters = new ( NFS_Allocate(1, sizeof(statistics_counters), NULL) ) statistics_counters;
222 #endif /* __TBB_STATISTICS */
223  }
225  ITT_SYNC_CREATE(&my_task_stream, SyncType_Scheduler, SyncObj_TaskStream);
226 #if __TBB_PREVIEW_CRITICAL_TASKS
227  my_critical_task_stream.initialize(my_num_slots);
228  ITT_SYNC_CREATE(&my_critical_task_stream, SyncType_Scheduler, SyncObj_CriticalTaskStream);
229 #endif
230 #if __TBB_ENQUEUE_ENFORCED_CONCURRENCY
231  my_concurrency_mode = cm_normal;
232 #endif
233 #if !__TBB_FP_CONTEXT
235 #endif
236 }
mail_outbox & mailbox(affinity_id id)
Get reference to mailbox corresponding to given affinity_id.
Definition: arena.h:204
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
unsigned my_num_reserved_slots
The number of reserved slots (can be occupied only by masters).
Definition: arena.h:152
unsigned my_max_num_workers
The number of workers requested by the master thread owning the arena.
Definition: arena.h:89
void construct()
Construct *this as a mailbox from zeroed memory.
Definition: mailbox.h:158
unsigned my_num_slots
The number of slots in the arena.
Definition: arena.h:149
cpu_ctl_env my_cpu_ctl_env
FPU control settings of arena's master thread captured at the moment of arena instantiation.
Definition: arena.h:138
static int unsigned num_arena_slots(unsigned num_slots)
Definition: arena.h:195
atomic< unsigned > my_references
Reference counter for the arena.
Definition: arena.h:57
void *__TBB_EXPORTED_FUNC NFS_Allocate(size_t n_element, size_t element_size, void *hint)
Allocate memory on cache/sector line boundary.
#define ITT_SYNC_CREATE(obj, type, name)
Definition: itt_notify.h:119
uintptr_t my_aba_epoch
ABA prevention marker.
Definition: arena.h:134
void initialize(unsigned n_lanes)
Definition: task_stream.h:83
size_t __TBB_EXPORTED_FUNC NFS_GetLineSize()
Cache/sector line size.
static const unsigned ref_external
Reference increment values for externals and workers.
Definition: arena.h:226
unsigned hint_for_pop
Hint provided for operations with the container of starvation-resistant tasks.
arena_slot my_slots[1]
Definition: arena.h:296
market * my_market
The market that owns this arena.
Definition: arena.h:131
task_stream< num_priority_levels > my_task_stream
Task pool for the tasks scheduled via task::enqueue() method.
Definition: arena.h:76
atomic< unsigned > my_limit
The maximal number of currently busy slots.
Definition: arena.h:65

References __TBB_ASSERT, tbb::internal::mail_outbox::construct(), tbb::internal::cpu_ctl_env::get_env(), tbb::internal::arena_slot_line2::hint_for_pop, tbb::internal::task_stream< Levels >::initialize(), ITT_SYNC_CREATE, mailbox(), tbb::internal::arena_base::my_aba_epoch, tbb::internal::market::my_arenas_aba_epoch, tbb::internal::arena_base::my_cpu_ctl_env, tbb::internal::arena_base::my_limit, tbb::internal::arena_base::my_market, tbb::internal::arena_base::my_max_num_workers, tbb::internal::arena_base::my_num_reserved_slots, tbb::internal::arena_base::my_num_slots, tbb::internal::arena_base::my_references, my_slots, tbb::internal::arena_base::my_task_stream, tbb::internal::NFS_Allocate(), tbb::internal::NFS_GetLineSize(), num_arena_slots(), and ref_external.

Referenced by allocate_arena().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ advertise_new_work()

template<arena::new_work_type work_type>
void tbb::internal::arena::advertise_new_work ( )

If necessary, raise a flag that there is new job in arena.

Definition at line 389 of file arena.h.

389  {
390  if( work_type == work_enqueued ) {
391 #if __TBB_ENQUEUE_ENFORCED_CONCURRENCY
393  if( my_concurrency_mode!=cm_enforced_global ) {
394  if( my_market->mandatory_concurrency_enable( this ) ) {
396  return;
397  }
398  }
399  } else if( my_max_num_workers==0 && my_num_reserved_slots==1 ) {
400  my_max_num_workers = 1;
401  __TBB_ASSERT(my_concurrency_mode==cm_normal, NULL);
402  my_concurrency_mode = cm_enforced_local;
404  my_market->adjust_demand( *this, 1 );
405  return;
406  }
407 #endif /* __TBB_ENQUEUE_ENFORCED_CONCURRENCY */
408  // Local memory fence here and below is required to avoid missed wakeups; see the comment below.
409  // Starvation resistant tasks require concurrency, so missed wakeups are unacceptable.
410  atomic_fence();
411  }
412  else if( work_type == wakeup ) {
413  __TBB_ASSERT(my_max_num_workers!=0, "Unexpected worker wakeup request");
414  atomic_fence();
415  }
416  // Double-check idiom that, in case of spawning, is deliberately sloppy about memory fences.
417  // Technically, to avoid missed wakeups, there should be a full memory fence between the point we
418  // released the task pool (i.e. spawned task) and read the arena's state. However, adding such a
419  // fence might hurt overall performance more than it helps, because the fence would be executed
420  // on every task pool release, even when stealing does not occur. Since TBB allows parallelism,
421  // but never promises parallelism, the missed wakeup is not a correctness problem.
422  pool_state_t snapshot = my_pool_state;
423  if( is_busy_or_empty(snapshot) ) {
424  // Attempt to mark as full. The compare_and_swap below is a little unusual because the
425  // result is compared to a value that can be different than the comparand argument.
427  if( snapshot!=SNAPSHOT_EMPTY ) {
428  // This thread read "busy" into snapshot, and then another thread transitioned
429  // my_pool_state to "empty" in the meantime, which caused the compare_and_swap above
430  // to fail. Attempt to transition my_pool_state from "empty" to "full".
432  // Some other thread transitioned my_pool_state from "empty", and hence became
433  // responsible for waking up workers.
434  return;
435  }
436  }
437  // This thread transitioned pool from empty to full state, and thus is responsible for
438  // telling the market that there is work to do.
439 #if __TBB_ENQUEUE_ENFORCED_CONCURRENCY
440  if( work_type == work_spawned ) {
441  if( my_concurrency_mode!=cm_normal ) {
442  switch( my_concurrency_mode ) {
443  case cm_enforced_local:
445  __TBB_ASSERT(!governor::local_scheduler()->is_worker(), "");
446  // There was deliberate oversubscription on 1 core for sake of starvation-resistant tasks.
447  // Now a single active thread (must be the master) supposedly starts a new parallel region
448  // with relaxed sequential semantics, and oversubscription should be avoided.
449  // Demand for workers has been decreased to 0 during SNAPSHOT_EMPTY, so just keep it.
450  my_max_num_workers = 0;
451  my_concurrency_mode = cm_normal;
452  break;
453  case cm_enforced_global:
454  my_market->mandatory_concurrency_disable( this );
456  break;
457  default:
458  break;
459  }
460  return;
461  }
462  }
463 #endif /* __TBB_ENQUEUE_ENFORCED_CONCURRENCY */
464  // TODO: investigate adjusting of arena's demand by a single worker.
466  }
467  }
468 }
static bool is_busy_or_empty(pool_state_t s)
No tasks to steal or snapshot is being taken.
Definition: arena.h:230
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
unsigned my_num_reserved_slots
The number of reserved slots (can be occupied only by masters).
Definition: arena.h:152
unsigned my_max_num_workers
The number of workers requested by the master thread owning the arena.
Definition: arena.h:89
static generic_scheduler * local_scheduler()
Obtain the thread-local instance of the TBB scheduler.
Definition: governor.h:122
uintptr_t pool_state_t
Definition: arena.h:214
tbb::atomic< uintptr_t > my_pool_state
Current task pool state and estimate of available tasks amount.
Definition: arena.h:99
static const pool_state_t SNAPSHOT_FULL
At least one task has been offered for stealing since the last snapshot started.
Definition: arena.h:220
void restore_priority_if_need()
If enqueued tasks found, restore arena priority and task presence status.
Definition: arena.cpp:383
void adjust_demand(arena &, int delta)
Request that arena's need in workers should be adjusted.
Definition: market.cpp:586
static const pool_state_t SNAPSHOT_EMPTY
No tasks to steal since last snapshot was taken.
Definition: arena.h:217
void atomic_fence()
Sequentially consistent full memory fence.
Definition: tbb_machine.h:339
unsigned my_num_workers_soft_limit
Current application-imposed limit on the number of workers (see set_active_num_workers())
Definition: market.h:78
market * my_market
The market that owns this arena.
Definition: arena.h:131
value_type compare_and_swap(value_type value, value_type comparand)
Definition: atomic.h:285

References __TBB_ASSERT, tbb::internal::market::adjust_demand(), tbb::atomic_fence(), tbb::internal::atomic_impl< T >::compare_and_swap(), is_busy_or_empty(), tbb::internal::governor::local_scheduler(), tbb::internal::arena_base::my_market, tbb::internal::arena_base::my_max_num_workers, tbb::internal::arena_base::my_num_reserved_slots, tbb::internal::market::my_num_workers_soft_limit, tbb::internal::arena_base::my_pool_state, restore_priority_if_need(), SNAPSHOT_EMPTY, SNAPSHOT_FULL, wakeup, work_enqueued, and work_spawned.

Referenced by tbb::internal::generic_scheduler::get_task(), tbb::internal::generic_scheduler::local_spawn(), and tbb::internal::generic_scheduler::steal_task_from().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ allocate_arena()

arena & tbb::internal::arena::allocate_arena ( market m,
unsigned  num_slots,
unsigned  num_reserved_slots 
)
static

Allocate an instance of arena.

Definition at line 238 of file arena.cpp.

238  {
239  __TBB_ASSERT( sizeof(base_type) + sizeof(arena_slot) == sizeof(arena), "All arena data fields must go to arena_base" );
240  __TBB_ASSERT( sizeof(base_type) % NFS_GetLineSize() == 0, "arena slots area misaligned: wrong padding" );
241  __TBB_ASSERT( sizeof(mail_outbox) == NFS_MaxLineSize, "Mailbox padding is wrong" );
242  size_t n = allocation_size(num_arena_slots(num_slots));
243  unsigned char* storage = (unsigned char*)NFS_Allocate( 1, n, NULL );
244  // Zero all slots to indicate that they are empty
245  memset( storage, 0, n );
246  return *new( storage + num_arena_slots(num_slots) * sizeof(mail_outbox) ) arena(m, num_slots, num_reserved_slots);
247 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
Definition: tbb_stddef.h:216
static int unsigned num_arena_slots(unsigned num_slots)
Definition: arena.h:195
void *__TBB_EXPORTED_FUNC NFS_Allocate(size_t n_element, size_t element_size, void *hint)
Allocate memory on cache/sector line boundary.
size_t __TBB_EXPORTED_FUNC NFS_GetLineSize()
Cache/sector line size.
static int allocation_size(unsigned num_slots)
Definition: arena.h:199
arena(market &, unsigned max_num_workers, unsigned num_reserved_slots)
Constructor.
Definition: arena.cpp:186
padded< arena_base > base_type
Definition: arena.h:180

References __TBB_ASSERT, allocation_size(), arena(), tbb::internal::NFS_Allocate(), tbb::internal::NFS_GetLineSize(), tbb::internal::NFS_MaxLineSize, and num_arena_slots().

Referenced by tbb::internal::market::create_arena().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ allocation_size()

static int tbb::internal::arena::allocation_size ( unsigned  num_slots)
inlinestatic

Definition at line 199 of file arena.h.

199  {
200  return sizeof(base_type) + num_slots * (sizeof(mail_outbox) + sizeof(arena_slot));
201  }
padded< arena_base > base_type
Definition: arena.h:180

Referenced by allocate_arena(), and free_arena().

Here is the caller graph for this function:

◆ enqueue_task()

void tbb::internal::arena::enqueue_task ( task t,
intptr_t  prio,
FastRandom random 
)

enqueue a task into starvation-resistance queue

Definition at line 554 of file arena.cpp.

555 {
556 #if __TBB_RECYCLE_TO_ENQUEUE
557  __TBB_ASSERT( t.state()==task::allocated || t.state()==task::to_enqueue, "attempt to enqueue task with inappropriate state" );
558 #else
559  __TBB_ASSERT( t.state()==task::allocated, "attempt to enqueue task that is not in 'allocated' state" );
560 #endif
561  t.prefix().state = task::ready;
562  t.prefix().extra_state |= es_task_enqueued; // enqueued task marker
563 
564 #if TBB_USE_ASSERT
565  if( task* parent = t.parent() ) {
566  internal::reference_count ref_count = parent->prefix().ref_count;
567  __TBB_ASSERT( ref_count!=0, "attempt to enqueue task whose parent has a ref_count==0 (forgot to set_ref_count?)" );
568  __TBB_ASSERT( ref_count>0, "attempt to enqueue task whose parent has a ref_count<0" );
569  parent->prefix().extra_state |= es_ref_count_active;
570  }
571  __TBB_ASSERT(t.prefix().affinity==affinity_id(0), "affinity is ignored for enqueued tasks");
572 #endif /* TBB_USE_ASSERT */
573 #if __TBB_PREVIEW_CRITICAL_TASKS
574  if( prio == internal::priority_critical || internal::is_critical( t ) ) {
575  // TODO: consider using of 'scheduler::handled_as_critical'
577 #if __TBB_TASK_ISOLATION
578  generic_scheduler* s = governor::local_scheduler_if_initialized();
579  __TBB_ASSERT( s, "Scheduler must be initialized at this moment" );
580  // propagate isolation level to critical task
581  t.prefix().isolation = s->my_innermost_running_task->prefix().isolation;
582 #endif
583  ITT_NOTIFY(sync_releasing, &my_critical_task_stream);
584  if( !s || !s->my_arena_slot ) {
585  // Either scheduler is not initialized or it is not attached to the arena, use random
586  // lane for the task.
587  my_critical_task_stream.push( &t, 0, internal::random_lane_selector(random) );
588  } else {
589  unsigned& lane = s->my_arena_slot->hint_for_critical;
590  my_critical_task_stream.push( &t, 0, tbb::internal::subsequent_lane_selector(lane) );
591  }
592  advertise_new_work<work_spawned>();
593  return;
594  }
595 #endif /* __TBB_PREVIEW_CRITICAL_TASKS */
596 
598 #if __TBB_TASK_PRIORITY
599  intptr_t p = prio ? normalize_priority(priority_t(prio)) : normalized_normal_priority;
600  assert_priority_valid(p);
601 #if __TBB_PREVIEW_CRITICAL_TASKS && __TBB_CPF_BUILD
602  my_task_stream.push( &t, p, internal::random_lane_selector(random) );
603 #else
604  my_task_stream.push( &t, p, random );
605 #endif
606  if ( p != my_top_priority )
607  my_market->update_arena_priority( *this, p );
608 #else /* !__TBB_TASK_PRIORITY */
609  __TBB_ASSERT_EX(prio == 0, "the library is not configured to respect the task priority");
610 #if __TBB_PREVIEW_CRITICAL_TASKS && __TBB_CPF_BUILD
611  my_task_stream.push( &t, 0, internal::random_lane_selector(random) );
612 #else
613  my_task_stream.push( &t, 0, random );
614 #endif
615 #endif /* !__TBB_TASK_PRIORITY */
616  advertise_new_work<work_enqueued>();
617 #if __TBB_TASK_PRIORITY
618  if ( p != my_top_priority )
619  my_market->update_arena_priority( *this, p );
620 #endif /* __TBB_TASK_PRIORITY */
621 }
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 parent
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 sync_releasing
#define __TBB_ASSERT_EX(predicate, comment)
"Extended" version is useful to suppress warnings if a variable is only used with an assert
Definition: tbb_stddef.h:167
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 * task
void const char const char int ITT_FORMAT __itt_group_sync s
bool is_critical(task &t)
Definition: task.h:958
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
task is in ready pool, or is going to be put there, or was just taken off.
Definition: task.h:615
intptr_t reference_count
A reference count.
Definition: task.h:117
Set if ref_count might be changed by another thread. Used for debugging.
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:116
void push(task *source, int level, FastRandom &random)
Push a task into a lane.
Definition: task_stream.h:101
static const int priority_critical
Definition: task.h:287
void make_critical(task &t)
Definition: task.h:957
unsigned short affinity_id
An id as used for specifying affinity.
Definition: task.h:120
void const char const char int ITT_FORMAT __itt_group_sync p
priority_t
Definition: task.h:291
market * my_market
The market that owns this arena.
Definition: arena.h:131
task object is freshly allocated or recycled.
Definition: task.h:617
task_stream< num_priority_levels > my_task_stream
Task pool for the tasks scheduled via task::enqueue() method.
Definition: arena.h:76
static generic_scheduler * local_scheduler_if_initialized()
Definition: governor.h:132

References __TBB_ASSERT, __TBB_ASSERT_EX, tbb::task::allocated, tbb::internal::es_ref_count_active, tbb::internal::es_task_enqueued, tbb::internal::is_critical(), ITT_NOTIFY, tbb::internal::governor::local_scheduler_if_initialized(), tbb::internal::make_critical(), tbb::internal::arena_base::my_market, tbb::internal::arena_base::my_task_stream, p, parent, tbb::task::parent(), tbb::task::prefix(), tbb::internal::priority_critical, tbb::internal::task_stream< Levels >::push(), tbb::task::ready, s, tbb::task::state(), and sync_releasing.

Referenced by tbb::internal::custom_scheduler< SchedulerTraits >::tally_completion_of_predecessor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_arena()

void tbb::internal::arena::free_arena ( )

Completes arena shutdown, destructs and deallocates it.

Definition at line 249 of file arena.cpp.

249  {
250  __TBB_ASSERT( is_alive(my_guard), NULL );
251  __TBB_ASSERT( !my_references, "There are threads in the dying arena" );
252  __TBB_ASSERT( !my_num_workers_requested && !my_num_workers_allotted, "Dying arena requests workers" );
253  __TBB_ASSERT( my_pool_state == SNAPSHOT_EMPTY || !my_max_num_workers, "Inconsistent state of a dying arena" );
254 #if __TBB_ENQUEUE_ENFORCED_CONCURRENCY
255  __TBB_ASSERT( my_concurrency_mode != cm_enforced_global, NULL );
256 #endif
257 #if !__TBB_STATISTICS_EARLY_DUMP
258  GATHER_STATISTIC( dump_arena_statistics() );
259 #endif
260  poison_value( my_guard );
261  intptr_t drained = 0;
262  for ( unsigned i = 0; i < my_num_slots; ++i ) {
263  __TBB_ASSERT( !my_slots[i].my_scheduler, "arena slot is not empty" );
264  // TODO: understand the assertion and modify
265  // __TBB_ASSERT( my_slots[i].task_pool == EmptyTaskPool, NULL );
266  __TBB_ASSERT( my_slots[i].head == my_slots[i].tail, NULL ); // TODO: replace by is_quiescent_local_task_pool_empty
268 #if __TBB_STATISTICS
269  NFS_Free( my_slots[i].my_counters );
270 #endif /* __TBB_STATISTICS */
271  drained += mailbox(i+1).drain();
272  }
273  __TBB_ASSERT( my_task_stream.drain()==0, "Not all enqueued tasks were executed");
274 #if __TBB_PREVIEW_CRITICAL_TASKS
275  __TBB_ASSERT( my_critical_task_stream.drain()==0, "Not all critical tasks were executed");
276 #endif
277 #if __TBB_COUNT_TASK_NODES
278  my_market->update_task_node_count( -drained );
279 #endif /* __TBB_COUNT_TASK_NODES */
280  // remove an internal reference
281  my_market->release( /*is_public=*/false, /*blocking_terminate=*/false );
282 #if __TBB_TASK_GROUP_CONTEXT
283  __TBB_ASSERT( my_default_ctx, "Master thread never entered the arena?" );
284  my_default_ctx->~task_group_context();
285  NFS_Free(my_default_ctx);
286 #endif /* __TBB_TASK_GROUP_CONTEXT */
287 #if __TBB_ARENA_OBSERVER
288  if ( !my_observers.empty() )
289  my_observers.clear();
290 #endif /* __TBB_ARENA_OBSERVER */
291  void* storage = &mailbox(my_num_slots);
292  __TBB_ASSERT( my_references == 0, NULL );
294  this->~arena();
295 #if TBB_USE_ASSERT > 1
296  memset( storage, 0, allocation_size(my_num_slots) );
297 #endif /* TBB_USE_ASSERT */
298  NFS_Free( storage );
299 }
void free_task_pool()
Deallocate task pool that was allocated by means of allocate_task_pool.
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 size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id tail
mail_outbox & mailbox(affinity_id id)
Get reference to mailbox corresponding to given affinity_id.
Definition: arena.h:204
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
unsigned my_max_num_workers
The number of workers requested by the master thread owning the arena.
Definition: arena.h:89
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
unsigned my_num_slots
The number of slots in the arena.
Definition: arena.h:149
tbb::atomic< uintptr_t > my_pool_state
Current task pool state and estimate of available tasks amount.
Definition: arena.h:99
int my_num_workers_requested
The number of workers that are currently requested from the resource manager.
Definition: arena.h:92
#define GATHER_STATISTIC(x)
atomic< unsigned > my_references
Reference counter for the arena.
Definition: arena.h:57
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 size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id head
intptr_t drain()
Destroys all remaining tasks in every lane. Returns the number of destroyed tasks.
Definition: task_stream.h:145
static int allocation_size(unsigned num_slots)
Definition: arena.h:199
arena(market &, unsigned max_num_workers, unsigned num_reserved_slots)
Constructor.
Definition: arena.cpp:186
static const pool_state_t SNAPSHOT_EMPTY
No tasks to steal since last snapshot was taken.
Definition: arena.h:217
unsigned my_num_workers_allotted
The number of workers that have been marked out by the resource manager to service the arena.
Definition: arena.h:51
arena_slot my_slots[1]
Definition: arena.h:296
market * my_market
The market that owns this arena.
Definition: arena.h:131
bool release(bool is_public, bool blocking_terminate)
Decrements market's refcount and destroys it in the end.
Definition: market.cpp:175
task_stream< num_priority_levels > my_task_stream
Task pool for the tasks scheduled via task::enqueue() method.
Definition: arena.h:76
intptr_t drain()
Drain the mailbox.
Definition: mailbox.h:168
#define poison_value(g)

References __TBB_ASSERT, allocation_size(), tbb::internal::task_stream< Levels >::drain(), tbb::internal::mail_outbox::drain(), tbb::internal::arena_slot::free_task_pool(), GATHER_STATISTIC, head, mailbox(), tbb::internal::arena_base::my_market, tbb::internal::arena_base::my_max_num_workers, tbb::internal::arena_base::my_num_slots, tbb::internal::arena_base::my_num_workers_allotted, tbb::internal::arena_base::my_num_workers_requested, tbb::internal::arena_base::my_pool_state, tbb::internal::arena_base::my_references, my_slots, tbb::internal::arena_base::my_task_stream, tbb::internal::NFS_Free(), poison_value, tbb::internal::market::release(), SNAPSHOT_EMPTY, and tail.

Referenced by tbb::internal::market::try_destroy_arena().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_enqueued_tasks()

bool tbb::internal::arena::has_enqueued_tasks ( )

Check for the presence of enqueued tasks at all priority levels.

Definition at line 375 of file arena.cpp.

375  {
376  // Look for enqueued tasks at all priority levels
377  for ( int p = 0; p < num_priority_levels; ++p )
378  if ( !my_task_stream.empty(p) )
379  return true;
380  return false;
381 }
static const intptr_t num_priority_levels
void const char const char int ITT_FORMAT __itt_group_sync p
bool empty(int level)
Checks existence of a task.
Definition: task_stream.h:138
task_stream< num_priority_levels > my_task_stream
Task pool for the tasks scheduled via task::enqueue() method.
Definition: arena.h:76

References tbb::internal::task_stream< Levels >::empty(), tbb::internal::arena_base::my_task_stream, tbb::internal::num_priority_levels, and p.

Referenced by restore_priority_if_need().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_busy_or_empty()

static bool tbb::internal::arena::is_busy_or_empty ( pool_state_t  s)
inlinestatic

No tasks to steal or snapshot is being taken.

Definition at line 230 of file arena.h.

230 { return s < SNAPSHOT_FULL; }
void const char const char int ITT_FORMAT __itt_group_sync s
static const pool_state_t SNAPSHOT_FULL
At least one task has been offered for stealing since the last snapshot started.
Definition: arena.h:220

References s, and SNAPSHOT_FULL.

Referenced by advertise_new_work().

Here is the caller graph for this function:

◆ is_out_of_work()

bool tbb::internal::arena::is_out_of_work ( )

Check if there is job anywhere in arena.

Return true if no job or if arena is being cleaned up.

Definition at line 403 of file arena.cpp.

403  {
404  // TODO: rework it to return at least a hint about where a task was found; better if the task itself.
405  for(;;) {
406  pool_state_t snapshot = my_pool_state;
407  switch( snapshot ) {
408  case SNAPSHOT_EMPTY:
409  return true;
410  case SNAPSHOT_FULL: {
411  // Use unique id for "busy" in order to avoid ABA problems.
412  const pool_state_t busy = pool_state_t(&busy);
413  // Request permission to take snapshot
415  // Got permission. Take the snapshot.
416  // NOTE: This is not a lock, as the state can be set to FULL at
417  // any moment by a thread that spawns/enqueues new task.
418  size_t n = my_limit;
419  // Make local copies of volatile parameters. Their change during
420  // snapshot taking procedure invalidates the attempt, and returns
421  // this thread into the dispatch loop.
422 #if __TBB_TASK_PRIORITY
423  uintptr_t reload_epoch = __TBB_load_with_acquire( my_reload_epoch );
424  intptr_t top_priority = my_top_priority;
425  // Inspect primary task pools first
426 #endif /* __TBB_TASK_PRIORITY */
427  size_t k;
428  for( k=0; k<n; ++k ) {
429  if( my_slots[k].task_pool != EmptyTaskPool &&
431  {
432  // k-th primary task pool is nonempty and does contain tasks.
433  break;
434  }
435  if( my_pool_state!=busy )
436  return false; // the work was published
437  }
438  __TBB_ASSERT( k <= n, NULL );
439  bool work_absent = k == n;
440 #if __TBB_PREVIEW_CRITICAL_TASKS
441  bool no_critical_tasks = my_critical_task_stream.empty(0);
442  work_absent &= no_critical_tasks;
443 #endif
444 #if __TBB_TASK_PRIORITY
445  // Variable tasks_present indicates presence of tasks at any priority
446  // level, while work_absent refers only to the current priority.
447  bool tasks_present = !work_absent || my_orphaned_tasks;
448  bool dequeuing_possible = false;
449  if ( work_absent ) {
450  // Check for the possibility that recent priority changes
451  // brought some tasks to the current priority level
452 
453  uintptr_t abandonment_epoch = my_abandonment_epoch;
454  // Master thread's scheduler needs special handling as it
455  // may be destroyed at any moment (workers' schedulers are
456  // guaranteed to be alive while at least one thread is in arena).
457  // The lock below excludes concurrency with task group state change
458  // propagation and guarantees lifetime of the master thread.
459  the_context_state_propagation_mutex.lock();
460  work_absent = !may_have_tasks( my_slots[0].my_scheduler, tasks_present, dequeuing_possible );
461  the_context_state_propagation_mutex.unlock();
462  // The following loop is subject to data races. While k-th slot's
463  // scheduler is being examined, corresponding worker can either
464  // leave to RML or migrate to another arena.
465  // But the races are not prevented because all of them are benign.
466  // First, the code relies on the fact that worker thread's scheduler
467  // object persists until the whole library is deinitialized.
468  // Second, in the worst case the races can only cause another
469  // round of stealing attempts to be undertaken. Introducing complex
470  // synchronization into this coldest part of the scheduler's control
471  // flow does not seem to make sense because it both is unlikely to
472  // ever have any observable performance effect, and will require
473  // additional synchronization code on the hotter paths.
474  for( k = 1; work_absent && k < n; ++k ) {
475  if( my_pool_state!=busy )
476  return false; // the work was published
477  work_absent = !may_have_tasks( my_slots[k].my_scheduler, tasks_present, dequeuing_possible );
478  }
479  // Preclude premature switching arena off because of a race in the previous loop.
480  work_absent = work_absent
481  && !__TBB_load_with_acquire(my_orphaned_tasks)
482  && abandonment_epoch == my_abandonment_epoch;
483  }
484 #endif /* __TBB_TASK_PRIORITY */
485  // Test and test-and-set.
486  if( my_pool_state==busy ) {
487 #if __TBB_TASK_PRIORITY
488  bool no_fifo_tasks = my_task_stream.empty(top_priority);
489  work_absent = work_absent && (!dequeuing_possible || no_fifo_tasks)
490  && top_priority == my_top_priority && reload_epoch == my_reload_epoch;
491 #else
492  bool no_fifo_tasks = my_task_stream.empty(0);
493  work_absent = work_absent && no_fifo_tasks;
494 #endif /* __TBB_TASK_PRIORITY */
495  if( work_absent ) {
496 #if __TBB_TASK_PRIORITY
497  if ( top_priority > my_bottom_priority ) {
498  if ( my_market->lower_arena_priority(*this, top_priority - 1, reload_epoch)
499  && !my_task_stream.empty(top_priority) )
500  {
501  atomic_update( my_skipped_fifo_priority, top_priority, std::less<intptr_t>());
502  }
503  }
504  else if ( !tasks_present && !my_orphaned_tasks && no_fifo_tasks ) {
505 #endif /* __TBB_TASK_PRIORITY */
506  // save current demand value before setting SNAPSHOT_EMPTY,
507  // to avoid race with advertise_new_work.
508  int current_demand = (int)my_max_num_workers;
509  if( my_pool_state.compare_and_swap( SNAPSHOT_EMPTY, busy )==busy ) {
510 #if __TBB_ENQUEUE_ENFORCED_CONCURRENCY
511  if( my_concurrency_mode==cm_enforced_global ) {
512  // adjust_demand() called inside, if needed
513  my_market->mandatory_concurrency_disable( this );
514  } else
515 #endif /* __TBB_ENQUEUE_ENFORCED_CONCURRENCY */
516  {
517  // This thread transitioned pool to empty state, and thus is
518  // responsible for telling the market that there is no work to do.
519  my_market->adjust_demand( *this, -current_demand );
520  }
522  return true;
523  }
524  return false;
525 #if __TBB_TASK_PRIORITY
526  }
527 #endif /* __TBB_TASK_PRIORITY */
528  }
529  // Undo previous transition SNAPSHOT_FULL-->busy, unless another thread undid it.
531  }
532  }
533  return false;
534  }
535  default:
536  // Another thread is taking a snapshot.
537  return false;
538  }
539  }
540 }
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 size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id tail
T1 atomic_update(tbb::atomic< T1 > &dst, T2 newValue, Pred compare)
Atomically replaces value of dst with newValue if they satisfy condition of compare predicate.
Definition: tbb_misc.h:179
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
unsigned my_max_num_workers
The number of workers requested by the master thread owning the arena.
Definition: arena.h:89
uintptr_t pool_state_t
Definition: arena.h:214
tbb::atomic< uintptr_t > my_pool_state
Current task pool state and estimate of available tasks amount.
Definition: arena.h:99
static const pool_state_t SNAPSHOT_FULL
At least one task has been offered for stealing since the last snapshot started.
Definition: arena.h:220
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 size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d int
void restore_priority_if_need()
If enqueued tasks found, restore arena priority and task presence status.
Definition: arena.cpp:383
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 size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id head
void adjust_demand(arena &, int delta)
Request that arena's need in workers should be adjusted.
Definition: market.cpp:586
T __TBB_load_relaxed(const volatile T &location)
Definition: tbb_machine.h:735
static const pool_state_t SNAPSHOT_EMPTY
No tasks to steal since last snapshot was taken.
Definition: arena.h:217
bool empty(int level)
Checks existence of a task.
Definition: task_stream.h:138
arena_slot my_slots[1]
Definition: arena.h:296
market * my_market
The market that owns this arena.
Definition: arena.h:131
T __TBB_load_with_acquire(const volatile T &location)
Definition: tbb_machine.h:709
task_stream< num_priority_levels > my_task_stream
Task pool for the tasks scheduled via task::enqueue() method.
Definition: arena.h:76
#define EmptyTaskPool
Definition: scheduler.h:42
value_type compare_and_swap(value_type value, value_type comparand)
Definition: atomic.h:285
atomic< unsigned > my_limit
The maximal number of currently busy slots.
Definition: arena.h:65

References __TBB_ASSERT, tbb::internal::__TBB_load_relaxed(), tbb::internal::__TBB_load_with_acquire(), tbb::internal::market::adjust_demand(), tbb::internal::atomic_update(), tbb::internal::atomic_impl< T >::compare_and_swap(), tbb::internal::task_stream< Levels >::empty(), EmptyTaskPool, head, int, tbb::internal::arena_base::my_limit, tbb::internal::arena_base::my_market, tbb::internal::arena_base::my_max_num_workers, tbb::internal::arena_base::my_pool_state, my_slots, tbb::internal::arena_base::my_task_stream, restore_priority_if_need(), SNAPSHOT_EMPTY, SNAPSHOT_FULL, and tail.

Referenced by on_thread_leaving().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mailbox()

mail_outbox& tbb::internal::arena::mailbox ( affinity_id  id)
inline

Get reference to mailbox corresponding to given affinity_id.

Definition at line 204 of file arena.h.

204  {
205  __TBB_ASSERT( 0<id, "affinity id must be positive integer" );
206  __TBB_ASSERT( id <= my_num_slots, "affinity id out of bounds" );
207 
208  return ((mail_outbox*)this)[-(int)id];
209  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
unsigned my_num_slots
The number of slots in the arena.
Definition: arena.h:149
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 size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d int

References __TBB_ASSERT, int, and tbb::internal::arena_base::my_num_slots.

Referenced by arena(), tbb::internal::generic_scheduler::attach_mailbox(), free_arena(), and tbb::internal::generic_scheduler::prepare_for_spawning().

Here is the caller graph for this function:

◆ num_arena_slots()

static int unsigned tbb::internal::arena::num_arena_slots ( unsigned  num_slots)
inlinestatic

Definition at line 195 of file arena.h.

195  {
196  return max(2u, num_slots);
197  }
T max(const T &val1, const T &val2)
Utility template function returning greater of the two values.
Definition: tbb_misc.h:112

References tbb::internal::max().

Referenced by allocate_arena(), arena(), and tbb::interface7::internal::task_arena_base::internal_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ num_workers_active()

unsigned tbb::internal::arena::num_workers_active ( )
inline

The number of workers active in the arena.

Definition at line 233 of file arena.h.

233  {
235  }
atomic< unsigned > my_references
Reference counter for the arena.
Definition: arena.h:57
static const unsigned ref_external_bits
The number of least significant bits for external references.
Definition: arena.h:223

References tbb::internal::arena_base::my_references, and ref_external_bits.

Referenced by tbb::internal::market::arena_in_need(), and process().

Here is the caller graph for this function:

◆ occupy_free_slot()

template<bool as_worker>
size_t tbb::internal::arena::occupy_free_slot ( generic_scheduler s)

Tries to occupy a slot in the arena. On success, returns the slot index; if no slot is available, returns out_of_arena.

Definition at line 86 of file arena.cpp.

86  {
87  // Firstly, masters try to occupy reserved slots
88  size_t index = as_worker ? out_of_arena : occupy_free_slot_in_range( s, 0, my_num_reserved_slots );
89  if ( index == out_of_arena ) {
90  // Secondly, all threads try to occupy all non-reserved slots
92  // Likely this arena is already saturated
93  if ( index == out_of_arena )
94  return out_of_arena;
95  }
96 
97  ITT_NOTIFY(sync_acquired, my_slots + index);
98  atomic_update( my_limit, (unsigned)(index + 1), std::less<unsigned>() );
99  return index;
100 }
void const char const char int ITT_FORMAT __itt_group_sync s
T1 atomic_update(tbb::atomic< T1 > &dst, T2 newValue, Pred compare)
Atomically replaces value of dst with newValue if they satisfy condition of compare predicate.
Definition: tbb_misc.h:179
unsigned my_num_reserved_slots
The number of reserved slots (can be occupied only by masters).
Definition: arena.h:152
unsigned my_num_slots
The number of slots in the arena.
Definition: arena.h:149
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:116
static const size_t out_of_arena
Definition: arena.h:288
size_t occupy_free_slot_in_range(generic_scheduler &s, size_t lower, size_t upper)
Tries to occupy a slot in the specified range.
Definition: arena.cpp:71
arena_slot my_slots[1]
Definition: arena.h:296
atomic< unsigned > my_limit
The maximal number of currently busy slots.
Definition: arena.h:65

References tbb::internal::atomic_update(), ITT_NOTIFY, tbb::internal::arena_base::my_limit, tbb::internal::arena_base::my_num_reserved_slots, tbb::internal::arena_base::my_num_slots, my_slots, occupy_free_slot_in_range(), out_of_arena, and s.

Referenced by process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ occupy_free_slot_in_range()

size_t tbb::internal::arena::occupy_free_slot_in_range ( generic_scheduler s,
size_t  lower,
size_t  upper 
)

Tries to occupy a slot in the specified range.

Definition at line 71 of file arena.cpp.

71  {
72  if ( lower >= upper ) return out_of_arena;
73  // Start search for an empty slot from the one we occupied the last time
74  size_t index = s.my_arena_index;
75  if ( index < lower || index >= upper ) index = s.my_random.get() % (upper - lower) + lower;
76  __TBB_ASSERT( index >= lower && index < upper, NULL );
77  // Find a free slot
78  for ( size_t i = index; i < upper; ++i )
79  if ( occupy_slot(my_slots[i].my_scheduler, s) ) return i;
80  for ( size_t i = lower; i < index; ++i )
81  if ( occupy_slot(my_slots[i].my_scheduler, s) ) return i;
82  return out_of_arena;
83 }
void const char const char int ITT_FORMAT __itt_group_sync s
static bool occupy_slot(generic_scheduler *&slot, generic_scheduler &s)
Definition: arena.cpp:67
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
static const size_t out_of_arena
Definition: arena.h:288
arena_slot my_slots[1]
Definition: arena.h:296

References __TBB_ASSERT, my_slots, tbb::internal::occupy_slot(), out_of_arena, and s.

Referenced by occupy_free_slot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_thread_leaving()

template<unsigned ref_param>
void tbb::internal::arena::on_thread_leaving ( )
inline

Notification that worker or master leaves its arena.

Definition at line 300 of file arena.h.

300  {
301  //
302  // Implementation of arena destruction synchronization logic contained various
303  // bugs/flaws at the different stages of its evolution, so below is a detailed
304  // description of the issues taken into consideration in the framework of the
305  // current design.
306  //
307  // In case of using fire-and-forget tasks (scheduled via task::enqueue())
308  // master thread is allowed to leave its arena before all its work is executed,
309  // and market may temporarily revoke all workers from this arena. Since revoked
310  // workers never attempt to reset arena state to EMPTY and cancel its request
311  // to RML for threads, the arena object is destroyed only when both the last
312  // thread is leaving it and arena's state is EMPTY (that is its master thread
313  // left and it does not contain any work).
314  // Thus resetting arena to EMPTY state (as earlier TBB versions did) should not
315  // be done here (or anywhere else in the master thread to that matter); doing so
316  // can result either in arena's premature destruction (at least without
317  // additional costly checks in workers) or in unnecessary arena state changes
318  // (and ensuing workers migration).
319  //
320  // A worker that checks for work presence and transitions arena to the EMPTY
321  // state (in snapshot taking procedure arena::is_out_of_work()) updates
322  // arena::my_pool_state first and only then arena::my_num_workers_requested.
323  // So the check for work absence must be done against the latter field.
324  //
325  // In a time window between decrementing the active threads count and checking
326  // if there is an outstanding request for workers. New worker thread may arrive,
327  // finish remaining work, set arena state to empty, and leave decrementing its
328  // refcount and destroying. Then the current thread will destroy the arena
329  // the second time. To preclude it a local copy of the outstanding request
330  // value can be stored before decrementing active threads count.
331  //
332  // But this technique may cause two other problem. When the stored request is
333  // zero, it is possible that arena still has threads and they can generate new
334  // tasks and thus re-establish non-zero requests. Then all the threads can be
335  // revoked (as described above) leaving this thread the last one, and causing
336  // it to destroy non-empty arena.
337  //
338  // The other problem takes place when the stored request is non-zero. Another
339  // thread may complete the work, set arena state to empty, and leave without
340  // arena destruction before this thread decrements the refcount. This thread
341  // cannot destroy the arena either. Thus the arena may be "orphaned".
342  //
343  // In both cases we cannot dereference arena pointer after the refcount is
344  // decremented, as our arena may already be destroyed.
345  //
346  // If this is the master thread, the market is protected by refcount to it.
347  // In case of workers market's liveness is ensured by the RML connection
348  // rundown protocol, according to which the client (i.e. the market) lives
349  // until RML server notifies it about connection termination, and this
350  // notification is fired only after all workers return into RML.
351  //
352  // Thus if we decremented refcount to zero we ask the market to check arena
353  // state (including the fact if it is alive) under the lock.
354  //
355  uintptr_t aba_epoch = my_aba_epoch;
356  market* m = my_market;
357  __TBB_ASSERT(my_references >= ref_param, "broken arena reference counter");
358 #if __TBB_STATISTICS_EARLY_DUMP
359  // While still holding a reference to the arena, compute how many external references are left.
360  // If just one, dump statistics.
361  if ( modulo_power_of_two(my_references,ref_worker)==ref_param ) // may only be true with ref_external
362  GATHER_STATISTIC( dump_arena_statistics() );
363 #endif
364 #if __TBB_ENQUEUE_ENFORCED_CONCURRENCY
365  // When there is no workers someone must free arena, as
366  // without workers, no one calls is_out_of_work().
367  // Skip workerless arenas because they have no demand for workers.
368  // TODO: consider more strict conditions for the cleanup,
369  // because it can create the demand of workers,
370  // but the arena can be already empty (and so ready for destroying)
371  if( ref_param==ref_external && my_num_slots != my_num_reserved_slots
372  && 0 == m->my_num_workers_soft_limit && my_concurrency_mode==cm_normal ) {
373  bool is_out = false;
374  for (int i=0; i<num_priority_levels; i++) {
375  is_out = is_out_of_work();
376  if (is_out)
377  break;
378  }
379  // We expect, that in worst case it's enough to have num_priority_levels-1
380  // calls to restore priorities and and yet another is_out_of_work() to conform
381  // that no work was found. But as market::set_active_num_workers() can be called
382  // concurrently, can't guarantee last is_out_of_work() return true.
383  }
384 #endif
385  if ( (my_references -= ref_param ) == 0 )
386  m->try_destroy_arena( this, aba_epoch );
387 }
argument_integer_type modulo_power_of_two(argument_integer_type arg, divisor_integer_type divisor)
A function to compute arg modulo divisor where divisor is a power of 2.
Definition: tbb_stddef.h:361
static const intptr_t num_priority_levels
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
unsigned my_num_reserved_slots
The number of reserved slots (can be occupied only by masters).
Definition: arena.h:152
unsigned my_num_slots
The number of slots in the arena.
Definition: arena.h:149
#define GATHER_STATISTIC(x)
atomic< unsigned > my_references
Reference counter for the arena.
Definition: arena.h:57
static const unsigned ref_worker
Definition: arena.h:227
uintptr_t my_aba_epoch
ABA prevention marker.
Definition: arena.h:134
static const unsigned ref_external
Reference increment values for externals and workers.
Definition: arena.h:226
market * my_market
The market that owns this arena.
Definition: arena.h:131
bool is_out_of_work()
Check if there is job anywhere in arena.
Definition: arena.cpp:403

References __TBB_ASSERT, GATHER_STATISTIC, is_out_of_work(), tbb::internal::modulo_power_of_two(), tbb::internal::arena_base::my_aba_epoch, tbb::internal::arena_base::my_market, tbb::internal::arena_base::my_num_reserved_slots, tbb::internal::arena_base::my_num_slots, tbb::internal::market::my_num_workers_soft_limit, tbb::internal::arena_base::my_references, tbb::internal::num_priority_levels, ref_external, ref_worker, and tbb::internal::market::try_destroy_arena().

Referenced by tbb::internal::generic_scheduler::cleanup_master(), and tbb::interface7::internal::task_arena_base::internal_initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

void tbb::internal::arena::process ( generic_scheduler s)

Registers the worker with the arena and enters TBB scheduler dispatch loop.

Definition at line 102 of file arena.cpp.

102  {
103  __TBB_ASSERT( is_alive(my_guard), NULL );
104  __TBB_ASSERT( governor::is_set(&s), NULL );
105  __TBB_ASSERT( s.my_innermost_running_task == s.my_dummy_task, NULL );
106  __TBB_ASSERT( s.worker_outermost_level(), NULL );
107 
108  __TBB_ASSERT( my_num_slots > 1, NULL );
109 
110  size_t index = occupy_free_slot</*as_worker*/true>( s );
111  if ( index == out_of_arena )
112  goto quit;
113 
114  __TBB_ASSERT( index >= my_num_reserved_slots, "Workers cannot occupy reserved slots" );
115  s.attach_arena( this, index, /*is_master*/false );
116 
117 #if !__TBB_FP_CONTEXT
119 #endif
120 
121 #if __TBB_ARENA_OBSERVER
122  __TBB_ASSERT( !s.my_last_local_observer, "There cannot be notified local observers when entering arena" );
123  my_observers.notify_entry_observers( s.my_last_local_observer, /*worker=*/true );
124 #endif /* __TBB_ARENA_OBSERVER */
125 
126  // Task pool can be marked as non-empty if the worker occupies the slot left by a master.
127  if ( s.my_arena_slot->task_pool != EmptyTaskPool ) {
128  __TBB_ASSERT( s.my_inbox.is_idle_state(false), NULL );
129  s.local_wait_for_all( *s.my_dummy_task, NULL );
130  __TBB_ASSERT( s.my_inbox.is_idle_state(true), NULL );
131  }
132 
133  for ( ;; ) {
134  __TBB_ASSERT( s.my_innermost_running_task == s.my_dummy_task, NULL );
135  __TBB_ASSERT( s.worker_outermost_level(), NULL );
136  __TBB_ASSERT( is_alive(my_guard), NULL );
137  __TBB_ASSERT( s.is_quiescent_local_task_pool_reset(),
138  "Worker cannot leave arena while its task pool is not reset" );
139  __TBB_ASSERT( s.my_arena_slot->task_pool == EmptyTaskPool, "Empty task pool is not marked appropriately" );
140  // This check prevents relinquishing more than necessary workers because
141  // of the non-atomicity of the decision making procedure
144  || recall_by_mandatory_request()
145 #endif
146  )
147  break;
148  // Try to steal a task.
149  // Passing reference count is technically unnecessary in this context,
150  // but omitting it here would add checks inside the function.
151  task* t = s.receive_or_steal_task( __TBB_ISOLATION_ARG( s.my_dummy_task->prefix().ref_count, no_isolation ) );
152  if (t) {
153  // A side effect of receive_or_steal_task is that my_innermost_running_task can be set.
154  // But for the outermost dispatch loop it has to be a dummy task.
155  s.my_innermost_running_task = s.my_dummy_task;
156  s.local_wait_for_all(*s.my_dummy_task,t);
157  }
158  }
159 #if __TBB_ARENA_OBSERVER
160  my_observers.notify_exit_observers( s.my_last_local_observer, /*worker=*/true );
161  s.my_last_local_observer = NULL;
162 #endif /* __TBB_ARENA_OBSERVER */
163 #if __TBB_TASK_PRIORITY
164  if ( s.my_offloaded_tasks )
165  orphan_offloaded_tasks( s );
166 #endif /* __TBB_TASK_PRIORITY */
167 #if __TBB_STATISTICS
168  ++s.my_counters.arena_roundtrips;
169  *my_slots[index].my_counters += s.my_counters;
170  s.my_counters.reset();
171 #endif /* __TBB_STATISTICS */
172  __TBB_store_with_release( my_slots[index].my_scheduler, (generic_scheduler*)NULL );
173  s.my_arena_slot = 0; // detached from slot
174  s.my_inbox.detach();
175  __TBB_ASSERT( s.my_inbox.is_idle_state(true), NULL );
176  __TBB_ASSERT( s.my_innermost_running_task == s.my_dummy_task, NULL );
177  __TBB_ASSERT( s.worker_outermost_level(), NULL );
178  __TBB_ASSERT( is_alive(my_guard), NULL );
179 quit:
180  // In contrast to earlier versions of TBB (before 3.0 U5) now it is possible
181  // that arena may be temporarily left unpopulated by threads. See comments in
182  // arena::on_thread_leaving() for more details.
183  on_thread_leaving<ref_worker>();
184 }
#define __TBB_ISOLATION_ARG(arg1, isolation)
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 * task
void const char const char int ITT_FORMAT __itt_group_sync s
void __TBB_store_with_release(volatile T &location, V value)
Definition: tbb_machine.h:713
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
unsigned my_num_reserved_slots
The number of reserved slots (can be occupied only by masters).
Definition: arena.h:152
unsigned my_num_slots
The number of slots in the arena.
Definition: arena.h:149
cpu_ctl_env my_cpu_ctl_env
FPU control settings of arena's master thread captured at the moment of arena instantiation.
Definition: arena.h:138
unsigned num_workers_active()
The number of workers active in the arena.
Definition: arena.h:233
const isolation_tag no_isolation
Definition: task.h:125
static bool is_set(generic_scheduler *s)
Used to check validity of the local scheduler TLS contents.
Definition: governor.cpp:120
static const size_t out_of_arena
Definition: arena.h:288
size_t occupy_free_slot(generic_scheduler &s)
Tries to occupy a slot in the arena. On success, returns the slot index; if no slot is available,...
Definition: arena.cpp:86
unsigned my_num_workers_allotted
The number of workers that have been marked out by the resource manager to service the arena.
Definition: arena.h:51
#define __TBB_ENQUEUE_ENFORCED_CONCURRENCY
Definition: tbb_config.h:577
arena_slot my_slots[1]
Definition: arena.h:296
#define EmptyTaskPool
Definition: scheduler.h:42

References __TBB_ASSERT, __TBB_ENQUEUE_ENFORCED_CONCURRENCY, __TBB_ISOLATION_ARG, tbb::internal::__TBB_store_with_release(), EmptyTaskPool, tbb::internal::governor::is_set(), tbb::internal::arena_base::my_cpu_ctl_env, tbb::internal::arena_base::my_num_reserved_slots, tbb::internal::arena_base::my_num_slots, tbb::internal::arena_base::my_num_workers_allotted, my_slots, tbb::internal::no_isolation, num_workers_active(), occupy_free_slot(), out_of_arena, s, and tbb::internal::cpu_ctl_env::set_env().

Referenced by tbb::internal::market::process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore_priority_if_need()

void tbb::internal::arena::restore_priority_if_need ( )
private

If enqueued tasks found, restore arena priority and task presence status.

Definition at line 383 of file arena.cpp.

383  {
384  // Check for the presence of enqueued tasks "lost" on some of
385  // priority levels because updating arena priority and switching
386  // arena into "populated" (FULL) state happen non-atomically.
387  // Imposing atomicity would require task::enqueue() to use a lock,
388  // which is unacceptable.
389  if ( has_enqueued_tasks() ) {
390  advertise_new_work<work_enqueued>();
391 #if __TBB_TASK_PRIORITY
392  // update_arena_priority() expects non-zero arena::my_num_workers_requested,
393  // so must be called after advertise_new_work<work_enqueued>()
394  for ( int p = 0; p < num_priority_levels; ++p )
395  if ( !my_task_stream.empty(p) ) {
396  if ( p < my_bottom_priority || p > my_top_priority )
397  my_market->update_arena_priority(*this, p);
398  }
399 #endif
400  }
401 }
bool has_enqueued_tasks()
Check for the presence of enqueued tasks at all priority levels.
Definition: arena.cpp:375
static const intptr_t num_priority_levels
void const char const char int ITT_FORMAT __itt_group_sync p
bool empty(int level)
Checks existence of a task.
Definition: task_stream.h:138
market * my_market
The market that owns this arena.
Definition: arena.h:131
task_stream< num_priority_levels > my_task_stream
Task pool for the tasks scheduled via task::enqueue() method.
Definition: arena.h:76

References tbb::internal::task_stream< Levels >::empty(), has_enqueued_tasks(), tbb::internal::arena_base::my_market, tbb::internal::arena_base::my_task_stream, tbb::internal::num_priority_levels, and p.

Referenced by advertise_new_work(), and is_out_of_work().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ my_slots

◆ out_of_arena

const size_t tbb::internal::arena::out_of_arena = ~size_t(0)
static

◆ ref_external

◆ ref_external_bits

const unsigned tbb::internal::arena::ref_external_bits = 12
static

The number of least significant bits for external references.

Definition at line 223 of file arena.h.

Referenced by num_workers_active().

◆ ref_worker

const unsigned tbb::internal::arena::ref_worker = 1<<ref_external_bits
static

Definition at line 227 of file arena.h.

Referenced by tbb::internal::market::arena_in_need(), and on_thread_leaving().

◆ SNAPSHOT_EMPTY

const pool_state_t tbb::internal::arena::SNAPSHOT_EMPTY = 0
static

◆ SNAPSHOT_FULL

const pool_state_t tbb::internal::arena::SNAPSHOT_FULL = pool_state_t(-1)
static

At least one task has been offered for stealing since the last snapshot started.

Definition at line 220 of file arena.h.

Referenced by advertise_new_work(), is_busy_or_empty(), and is_out_of_work().


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

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.