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 179 of file arena.h.

Member Typedef Documentation

◆ base_type

Definition at line 184 of file arena.h.

◆ pool_state_t

Definition at line 218 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 187 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 190 of file arena.cpp.

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

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 393 of file arena.h.

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

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 242 of file arena.cpp.

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

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 203 of file arena.h.

203  {
204  return sizeof(base_type) + num_slots * (sizeof(mail_outbox) + sizeof(arena_slot));
205  }
padded< arena_base > base_type
Definition: arena.h:184

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 558 of file arena.cpp.

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

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 253 of file arena.cpp.

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

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 379 of file arena.cpp.

379  {
380  // Look for enqueued tasks at all priority levels
381  for ( int p = 0; p < num_priority_levels; ++p )
382  if ( !my_task_stream.empty(p) )
383  return true;
384  return false;
385 }
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:142
static const intptr_t num_priority_levels
task_stream< num_priority_levels > my_task_stream
Task pool for the tasks scheduled via task::enqueue() method.
Definition: arena.h:80

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 234 of file arena.h.

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

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 407 of file arena.cpp.

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

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 208 of file arena.h.

208  {
209  __TBB_ASSERT( 0<id, "affinity id must be positive integer" );
210  __TBB_ASSERT( id <= my_num_slots, "affinity id out of bounds" );
211 
212  return ((mail_outbox*)this)[-(int)id];
213  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
unsigned my_num_slots
The number of slots in the arena.
Definition: arena.h:153
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 199 of file arena.h.

199  {
200  return max(2u, num_slots);
201  }
T max(const T &val1, const T &val2)
Utility template function returning greater of the two values.
Definition: tbb_misc.h:116

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 237 of file arena.h.

237  {
239  }
atomic< unsigned > my_references
Reference counter for the arena.
Definition: arena.h:61
static const unsigned ref_external_bits
The number of least significant bits for external references.
Definition: arena.h:227

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 90 of file arena.cpp.

90  {
91  // Firstly, masters try to occupy reserved slots
92  size_t index = as_worker ? out_of_arena : occupy_free_slot_in_range( s, 0, my_num_reserved_slots );
93  if ( index == out_of_arena ) {
94  // Secondly, all threads try to occupy all non-reserved slots
96  // Likely this arena is already saturated
97  if ( index == out_of_arena )
98  return out_of_arena;
99  }
100 
101  ITT_NOTIFY(sync_acquired, my_slots + index);
102  atomic_update( my_limit, (unsigned)(index + 1), std::less<unsigned>() );
103  return index;
104 }
unsigned my_num_reserved_slots
The number of reserved slots (can be occupied only by masters).
Definition: arena.h:156
static const size_t out_of_arena
Definition: arena.h:292
unsigned my_num_slots
The number of slots in the arena.
Definition: arena.h:153
arena_slot my_slots[1]
Definition: arena.h:300
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:75
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:183
atomic< unsigned > my_limit
The maximal number of currently busy slots.
Definition: arena.h:69
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:120
void const char const char int ITT_FORMAT __itt_group_sync s

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 75 of file arena.cpp.

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

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 304 of file arena.h.

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

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 106 of file arena.cpp.

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

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 387 of file arena.cpp.

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

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 227 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 231 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 224 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.