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

#include <task_arena.h>

Inheritance diagram for tbb::interface7::internal::task_arena_base:
Collaboration diagram for tbb::interface7::internal::task_arena_base:

Static Public Attributes

static const int automatic = -1
 Typedef for number of threads that is automatic. More...
 
static const int not_initialized = -2
 

Protected Types

enum  { default_flags, exact_exception_flag = task_group_context::exact_exception }
 

Protected Member Functions

 task_arena_base (int max_concurrency, unsigned reserved_for_masters)
 
void __TBB_EXPORTED_METHOD internal_initialize ()
 
void __TBB_EXPORTED_METHOD internal_terminate ()
 
void __TBB_EXPORTED_METHOD internal_attach ()
 
void __TBB_EXPORTED_METHOD internal_enqueue (task &, intptr_t) const
 
void __TBB_EXPORTED_METHOD internal_execute (delegate_base &) const
 
void __TBB_EXPORTED_METHOD internal_wait () const
 

Static Protected Member Functions

static int __TBB_EXPORTED_FUNC internal_current_slot ()
 
static int __TBB_EXPORTED_FUNC internal_max_concurrency (const task_arena *)
 

Protected Attributes

internal::arena * my_arena
 NULL if not currently initialized. More...
 
task_group_contextmy_context
 default context of the arena More...
 
int my_max_concurrency
 Concurrency level for deferred initialization. More...
 
unsigned my_master_slots
 Reserved master slots. More...
 
intptr_t my_version_and_traits
 Special settings. More...
 

Detailed Description

Definition at line 103 of file task_arena.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
default_flags 
exact_exception_flag 

Definition at line 122 of file task_arena.h.

Constructor & Destructor Documentation

◆ task_arena_base()

tbb::interface7::internal::task_arena_base::task_arena_base ( int  max_concurrency,
unsigned  reserved_for_masters 
)
inlineprotected

Definition at line 130 of file task_arena.h.

131  : my_arena(0)
132 #if __TBB_TASK_GROUP_CONTEXT
133  , my_context(0)
134 #endif
136  , my_master_slots(reserved_for_masters)
138  {}
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
int max_concurrency()
Returns the maximal number of threads that can work inside the arena.
Definition: task_arena.h:402
intptr_t my_version_and_traits
Special settings.
Definition: task_arena.h:120
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:114
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106
unsigned my_master_slots
Reserved master slots.
Definition: task_arena.h:117

Member Function Documentation

◆ internal_attach()

void tbb::interface7::internal::task_arena_base::internal_attach ( )
protected

Definition at line 732 of file arena.cpp.

732  {
733  __TBB_ASSERT(!my_arena, NULL);
734  generic_scheduler* s = governor::local_scheduler_if_initialized();
735  if( s && s->my_arena ) {
736  // There is an active arena to attach to.
737  // It's still used by s, so won't be destroyed right away.
738  my_arena = s->my_arena;
739  __TBB_ASSERT( my_arena->my_references > 0, NULL );
740  my_arena->my_references += arena::ref_external;
741 #if __TBB_TASK_GROUP_CONTEXT
742  my_context = my_arena->my_default_ctx;
744 #endif
745  my_master_slots = my_arena->my_num_reserved_slots;
746  my_max_concurrency = my_master_slots + my_arena->my_max_num_workers;
748  // increases market's ref count for task_arena
749  market::global_market( /*is_public=*/true );
750  }
751 }
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
void const char const char int ITT_FORMAT __itt_group_sync s
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
static market & global_market(bool is_public, unsigned max_num_workers=0, size_t stack_size=0)
Factory method creating new market object.
Definition: market.cpp:100
static int unsigned num_arena_slots(unsigned num_slots)
Definition: arena.h:182
static const unsigned ref_external
Reference increment values for externals and workers.
Definition: arena.h:213
static generic_scheduler * local_scheduler_if_initialized()
Definition: governor.h:136
intptr_t my_version_and_traits
Special settings.
Definition: task_arena.h:120
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:114
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106
uintptr_t my_version_and_traits
Version for run-time checks and behavioral traits of the context.
Definition: task.h:407
unsigned my_master_slots
Reserved master slots.
Definition: task_arena.h:117

References __TBB_ASSERT, exact_exception_flag, tbb::internal::market::global_market(), tbb::internal::governor::local_scheduler_if_initialized(), my_arena, my_context, my_master_slots, my_max_concurrency, my_version_and_traits, tbb::task_group_context::my_version_and_traits, tbb::internal::arena::num_arena_slots(), tbb::internal::arena::ref_external, and s.

Here is the call graph for this function:

◆ internal_current_slot()

int tbb::interface7::internal::task_arena_base::internal_current_slot ( )
staticprotected

Definition at line 967 of file arena.cpp.

967  {
968  generic_scheduler* s = governor::local_scheduler_if_initialized();
969  return s? int(s->my_arena_index) : -1;
970 }
void const char const char int ITT_FORMAT __itt_group_sync s
static generic_scheduler * local_scheduler_if_initialized()
Definition: governor.h:136
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 int, tbb::internal::governor::local_scheduler_if_initialized(), and s.

Here is the call graph for this function:

◆ internal_enqueue()

void tbb::interface7::internal::task_arena_base::internal_enqueue ( task t,
intptr_t  prio 
) const
protected

Definition at line 753 of file arena.cpp.

753  {
754  __TBB_ASSERT(my_arena, NULL);
755  generic_scheduler* s = governor::local_scheduler_if_initialized();
756  __TBB_ASSERT(s, "Scheduler is not initialized"); // we allocated a task so can expect the scheduler
757 #if __TBB_TASK_GROUP_CONTEXT
758  __TBB_ASSERT(my_arena->my_default_ctx == t.prefix().context, NULL);
759  __TBB_ASSERT(!my_arena->my_default_ctx->is_group_execution_cancelled(), // TODO: any better idea?
760  "The task will not be executed because default task_group_context of task_arena is cancelled. Has previously enqueued task thrown an exception?");
761 #endif
762  my_arena->enqueue_task( t, prio, s->my_random );
763 }
void const char const char int ITT_FORMAT __itt_group_sync s
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
static generic_scheduler * local_scheduler_if_initialized()
Definition: governor.h:136
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106

References __TBB_ASSERT, tbb::internal::governor::local_scheduler_if_initialized(), my_arena, tbb::task::prefix(), and s.

Referenced by internal_execute(), and internal_wait().

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

◆ internal_execute()

void tbb::interface7::internal::task_arena_base::internal_execute ( delegate_base ) const
protected

Definition at line 814 of file arena.cpp.

814  {
815  __TBB_ASSERT(my_arena, NULL);
816  generic_scheduler* s = governor::local_scheduler_weak();
817  __TBB_ASSERT(s, "Scheduler is not initialized");
818 
819  bool same_arena = s->my_arena == my_arena;
820  size_t index1 = s->my_arena_index;
821  if (!same_arena) {
822  index1 = my_arena->occupy_free_slot</* as_worker*/false>(*s);
823  if (index1 == arena::out_of_arena) {
824 
825 #if __TBB_USE_OPTIONAL_RTTI
826  // Workaround for the bug inside graph. If the thread can not occupy arena slot during task_arena::execute()
827  // and all aggregator operations depend on this task completion (all other threads are inside arena already)
828  // deadlock appears, because enqueued task will never enter arena.
829  // Workaround: check if the task came from graph via RTTI (casting to graph::spawn_functor)
830  // and enqueue this task with non-blocking internal_enqueue method.
831  // TODO: have to change behaviour later in next GOLD release (maybe to add new library entry point - try_execute)
833  internal::delegated_function< graph_funct, void >* deleg_funct =
834  dynamic_cast< internal::delegated_function< graph_funct, void>* >(&d);
835 
836  if (deleg_funct) {
838  internal::function_task< internal::strip< graph_funct >::type >
839  (internal::forward< graph_funct >(deleg_funct->my_func)), 0);
840  return;
841  } else {
842 #endif /* __TBB_USE_OPTIONAL_RTTI */
843  concurrent_monitor::thread_context waiter;
844 #if __TBB_TASK_GROUP_CONTEXT
845  task_group_context exec_context(task_group_context::isolated, my_version_and_traits & exact_exception_flag);
846 #if __TBB_FP_CONTEXT
847  exec_context.copy_fp_settings(*my_context);
848 #endif
849 #endif
850  auto_empty_task root(__TBB_CONTEXT_ARG(s, &exec_context));
851  root.prefix().ref_count = 2;
852  my_arena->enqueue_task(*new(task::allocate_root(__TBB_CONTEXT_ARG1(exec_context)))
853  delegated_task(d, my_arena->my_exit_monitors, &root),
854  0, s->my_random); // TODO: priority?
855  size_t index2 = arena::out_of_arena;
856  do {
857  my_arena->my_exit_monitors.prepare_wait(waiter, (uintptr_t)&d);
858  if (__TBB_load_with_acquire(root.prefix().ref_count) < 2) {
859  my_arena->my_exit_monitors.cancel_wait(waiter);
860  break;
861  }
862  index2 = my_arena->occupy_free_slot</*as_worker*/false>(*s);
863  if (index2 != arena::out_of_arena) {
864  my_arena->my_exit_monitors.cancel_wait(waiter);
865  nested_arena_context scope(s, my_arena, index2, scheduler_properties::master, same_arena);
866  s->local_wait_for_all(root, NULL);
867 #if TBB_USE_EXCEPTIONS
868  __TBB_ASSERT(!exec_context.my_exception, NULL); // exception can be thrown above, not deferred
869 #endif
870  __TBB_ASSERT(root.prefix().ref_count == 0, NULL);
871  break;
872  }
873  my_arena->my_exit_monitors.commit_wait(waiter);
874  } while (__TBB_load_with_acquire(root.prefix().ref_count) == 2);
875  if (index2 == arena::out_of_arena) {
876  // notify a waiting thread even if this thread did not enter arena,
877  // in case it was woken by a leaving thread but did not need to enter
878  my_arena->my_exit_monitors.notify_one(); // do not relax!
879  }
880 #if TBB_USE_EXCEPTIONS
881  // process possible exception
882  if (task_group_context::exception_container_type *pe = exec_context.my_exception)
883  TbbRethrowException(pe);
884 #endif
885  return;
886 #if __TBB_USE_OPTIONAL_RTTI
887  } // if task came from graph
888 #endif
889  } // if (index1 == arena::out_of_arena)
890  } // if (!same_arena)
891 
892  context_guard_helper</*report_tasks=*/false> context_guard;
893  context_guard.set_ctx(__TBB_CONTEXT_ARG1(my_context));
894 #if TBB_USE_EXCEPTIONS
895  try {
896 #endif
897  //TODO: replace dummy tasks for workers as well to avoid using of the_dummy_context
898  nested_arena_context scope(s, my_arena, index1, scheduler_properties::master, same_arena);
899  d();
900 #if TBB_USE_EXCEPTIONS
901  }
902  catch (...) {
903  context_guard.restore_default(); // TODO: is it needed on Windows?
905  else {
906  task_group_context exception_container(task_group_context::isolated,
908  exception_container.register_pending_exception();
909  __TBB_ASSERT(exception_container.my_exception, NULL);
910  TbbRethrowException(exception_container.my_exception);
911  }
912  }
913 #endif
914 }
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
void const char const char int ITT_FORMAT __itt_group_sync s
#define __TBB_CONTEXT_ARG1(context)
internal::tbb_exception_ptr exception_container_type
Definition: task.h:328
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
void const char const char int ITT_FORMAT __itt_group_sync 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 __itt_event ITT_FORMAT __itt_group_mark d void const wchar_t const wchar_t int ITT_FORMAT __itt_group_sync __itt_group_fsync x void const wchar_t int const wchar_t int int ITT_FORMAT __itt_group_sync __itt_group_fsync x void ITT_FORMAT __itt_group_sync __itt_group_fsync p void ITT_FORMAT __itt_group_sync __itt_group_fsync p void size_t ITT_FORMAT lu no args __itt_obj_prop_t __itt_obj_state_t ITT_FORMAT d const char ITT_FORMAT s __itt_frame ITT_FORMAT p const char const char ITT_FORMAT s __itt_counter ITT_FORMAT p __itt_counter unsigned long long ITT_FORMAT lu const wchar_t ITT_FORMAT S __itt_mark_type const wchar_t ITT_FORMAT S __itt_mark_type const char ITT_FORMAT s __itt_mark_type ITT_FORMAT d __itt_caller ITT_FORMAT p __itt_caller ITT_FORMAT p no args const __itt_domain __itt_clock_domain unsigned long long __itt_id ITT_FORMAT lu const __itt_domain __itt_clock_domain unsigned long long __itt_id __itt_id void ITT_FORMAT p const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_clock_domain unsigned long long __itt_id __itt_string_handle __itt_scope scope
static const size_t out_of_arena
Definition: arena.h:275
T __TBB_load_with_acquire(const volatile T &location)
Definition: tbb_machine.h:713
intptr_t my_version_and_traits
Special settings.
Definition: task_arena.h:120
static generic_scheduler * local_scheduler_weak()
Definition: governor.h:131
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d
void __TBB_EXPORTED_METHOD internal_enqueue(task &, intptr_t) const
Definition: arena.cpp:753
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106
#define __TBB_CONTEXT_ARG(arg1, context)
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:620

References __TBB_ASSERT, __TBB_CONTEXT_ARG, __TBB_CONTEXT_ARG1, tbb::internal::__TBB_load_with_acquire(), tbb::task::allocate_root(), tbb::task_group_context::copy_fp_settings(), d, tbb::task_group_context::default_traits, tbb::task_group_context::exact_exception, exact_exception_flag, internal_enqueue(), tbb::task_group_context::isolated, tbb::internal::governor::local_scheduler_weak(), tbb::internal::scheduler_properties::master, my_arena, my_context, tbb::task_group_context::my_exception, my_version_and_traits, tbb::internal::arena::out_of_arena, tbb::internal::auto_empty_task::prefix(), tbb::internal::task_prefix::ref_count, tbb::task_group_context::register_pending_exception(), tbb::internal::context_guard_helper< T >::restore_default(), s, scope, and tbb::internal::context_guard_helper< T >::set_ctx().

Here is the call graph for this function:

◆ internal_initialize()

void tbb::interface7::internal::task_arena_base::internal_initialize ( )
protected

Definition at line 688 of file arena.cpp.

688  {
690  if( my_max_concurrency < 1 )
692  __TBB_ASSERT( my_master_slots <= (unsigned)my_max_concurrency, "Number of slots reserved for master should not exceed arena concurrency");
693  arena* new_arena = market::create_arena( my_max_concurrency, my_master_slots, 0 );
694  // add an internal market reference; a public reference was added in create_arena
695  market &m = market::global_market( /*is_public=*/false );
696  // allocate default context for task_arena
697 #if __TBB_TASK_GROUP_CONTEXT
698  new_arena->my_default_ctx = new ( NFS_Allocate(1, sizeof(task_group_context), NULL) )
700 #if __TBB_FP_CONTEXT
701  new_arena->my_default_ctx->capture_fp_settings();
702 #endif
703 #endif /* __TBB_TASK_GROUP_CONTEXT */
704  // threads might race to initialize the arena
705  if(as_atomic(my_arena).compare_and_swap(new_arena, NULL) != NULL) {
706  __TBB_ASSERT(my_arena, NULL); // another thread won the race
707  // release public market reference
708  m.release( /*is_public=*/true, /*blocking_terminate=*/false );
709  new_arena->on_thread_leaving<arena::ref_external>(); // destroy unneeded arena
710 #if __TBB_TASK_GROUP_CONTEXT
711  spin_wait_while_eq(my_context, (task_group_context*)NULL);
712  } else {
713  new_arena->my_default_ctx->my_version_and_traits |= my_version_and_traits & exact_exception_flag;
714  as_atomic(my_context) = new_arena->my_default_ctx;
715 #endif
716  }
717  // TODO: should it trigger automatic initialization of this thread?
719 }
static unsigned default_num_threads()
Definition: governor.h:85
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
atomic< T > & as_atomic(T &t)
Definition: atomic.h:547
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
static market & global_market(bool is_public, unsigned max_num_workers=0, size_t stack_size=0)
Factory method creating new market object.
Definition: market.cpp:100
static const unsigned ref_external
Reference increment values for externals and workers.
Definition: arena.h:213
intptr_t my_version_and_traits
Special settings.
Definition: task_arena.h:120
static generic_scheduler * local_scheduler_weak()
Definition: governor.h:131
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:114
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106
static arena * create_arena(int num_slots, int num_reserved_slots, size_t stack_size)
Creates an arena object.
Definition: market.cpp:300
unsigned my_master_slots
Reserved master slots.
Definition: task_arena.h:117
void *__TBB_EXPORTED_FUNC NFS_Allocate(size_t n_element, size_t element_size, void *hint)
Allocate memory on cache/sector line boundary.
void spin_wait_while_eq(const volatile T &location, U value)
Spin WHILE the value of the variable is equal to a given value.
Definition: tbb_machine.h:395
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
static void one_time_init()
Definition: governor.cpp:160

References __TBB_ASSERT, tbb::internal::as_atomic(), tbb::internal::market::create_arena(), tbb::internal::governor::default_num_threads(), tbb::task_group_context::default_traits, exact_exception_flag, tbb::internal::market::global_market(), int, tbb::task_group_context::isolated, tbb::internal::governor::local_scheduler_weak(), my_arena, my_context, my_master_slots, my_max_concurrency, my_version_and_traits, tbb::internal::NFS_Allocate(), tbb::internal::arena::on_thread_leaving(), tbb::internal::governor::one_time_init(), tbb::internal::arena::ref_external, tbb::internal::market::release(), and tbb::internal::spin_wait_while_eq().

Here is the call graph for this function:

◆ internal_max_concurrency()

int tbb::interface7::internal::task_arena_base::internal_max_concurrency ( const task_arena ta)
staticprotected

Definition at line 998 of file arena.cpp.

998  {
999  arena* a = NULL;
1000  if( ta ) // for special cases of ta->max_concurrency()
1001  a = ta->my_arena;
1002  else if( generic_scheduler* s = governor::local_scheduler_if_initialized() )
1003  a = s->my_arena; // the current arena if any
1004 
1005  if( a ) { // Get parameters from the arena
1006  __TBB_ASSERT( !ta || ta->my_max_concurrency==1, NULL );
1007  return a->my_num_reserved_slots + a->my_max_num_workers;
1008  } else {
1009  __TBB_ASSERT( !ta || ta->my_max_concurrency==automatic, NULL );
1011  }
1012 }
static unsigned default_num_threads()
Definition: governor.h:85
void const char const char int ITT_FORMAT __itt_group_sync s
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
static generic_scheduler * local_scheduler_if_initialized()
Definition: governor.h:136
static const int automatic
Typedef for number of threads that is automatic.
Definition: task_arena.h:150
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, automatic, tbb::internal::governor::default_num_threads(), int, tbb::internal::governor::local_scheduler_if_initialized(), my_arena, my_max_concurrency, tbb::internal::arena_base::my_max_num_workers, tbb::internal::arena_base::my_num_reserved_slots, and s.

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

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

◆ internal_terminate()

void tbb::interface7::internal::task_arena_base::internal_terminate ( )
protected

Definition at line 721 of file arena.cpp.

721  {
722  if( my_arena ) {// task_arena was initialized
723  my_arena->my_market->release( /*is_public=*/true, /*blocking_terminate=*/false );
724  my_arena->on_thread_leaving<arena::ref_external>();
725  my_arena = 0;
726 #if __TBB_TASK_GROUP_CONTEXT
727  my_context = 0;
728 #endif
729  }
730 }
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
static const unsigned ref_external
Reference increment values for externals and workers.
Definition: arena.h:213
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106

References my_arena, my_context, and tbb::internal::arena::ref_external.

◆ internal_wait()

void tbb::interface7::internal::task_arena_base::internal_wait ( ) const
protected

Definition at line 938 of file arena.cpp.

938  {
939  __TBB_ASSERT(my_arena, NULL);
940  generic_scheduler* s = governor::local_scheduler_weak();
941  __TBB_ASSERT(s, "Scheduler is not initialized");
942  __TBB_ASSERT(s->my_arena != my_arena || s->my_arena_index == 0, "task_arena::wait_until_empty() is not supported within a worker context" );
943  if( s->my_arena == my_arena ) {
944  //unsupported, but try do something for outermost master
945  __TBB_ASSERT(s->master_outermost_level(), "unsupported");
946  if( !s->my_arena_index )
947  while( my_arena->num_workers_active() )
948  s->wait_until_empty();
949  } else for(;;) {
950  while( my_arena->my_pool_state != arena::SNAPSHOT_EMPTY ) {
951  if( !__TBB_load_with_acquire(my_arena->my_slots[0].my_scheduler) // TODO TEMP: one master, make more masters
952  && as_atomic(my_arena->my_slots[0].my_scheduler).compare_and_swap(s, NULL) == NULL ) {
953  nested_arena_context a(s, my_arena, 0, scheduler_properties::worker, false);
954  s->wait_until_empty();
955  } else {
956  binary_semaphore waiter; // TODO: replace by a single event notification from is_out_of_work
957  internal_enqueue( *new( task::allocate_root(__TBB_CONTEXT_ARG1(*my_context)) ) wait_task(waiter), 0 ); // TODO: priority?
958  waiter.P(); // TODO: concurrent_monitor
959  }
960  }
961  if( !my_arena->num_workers_active() && !my_arena->my_slots[0].my_scheduler) // no activity
962  break; // spin until workers active but avoid spinning in a worker
963  __TBB_Yield(); // wait until workers and master leave
964  }
965 }
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
atomic< T > & as_atomic(T &t)
Definition: atomic.h:547
void const char const char int ITT_FORMAT __itt_group_sync s
#define __TBB_CONTEXT_ARG1(context)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
T __TBB_load_with_acquire(const volatile T &location)
Definition: tbb_machine.h:713
static const pool_state_t SNAPSHOT_EMPTY
No tasks to steal since last snapshot was taken.
Definition: arena.h:204
static generic_scheduler * local_scheduler_weak()
Definition: governor.h:131
void __TBB_EXPORTED_METHOD internal_enqueue(task &, intptr_t) const
Definition: arena.cpp:753
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106
#define __TBB_Yield()
Definition: ibm_aix51.h:48
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:620

References __TBB_ASSERT, __TBB_CONTEXT_ARG1, tbb::internal::__TBB_load_with_acquire(), __TBB_Yield, tbb::task::allocate_root(), tbb::internal::as_atomic(), internal_enqueue(), tbb::internal::governor::local_scheduler_weak(), my_arena, my_context, tbb::internal::binary_semaphore::P(), s, tbb::internal::arena::SNAPSHOT_EMPTY, and tbb::internal::scheduler_properties::worker.

Here is the call graph for this function:

Member Data Documentation

◆ automatic

const int tbb::interface7::internal::task_arena_base::automatic = -1
static

Typedef for number of threads that is automatic.

Definition at line 150 of file task_arena.h.

Referenced by internal_max_concurrency().

◆ my_arena

internal::arena* tbb::interface7::internal::task_arena_base::my_arena
protected

◆ my_context

task_group_context* tbb::interface7::internal::task_arena_base::my_context
protected

default context of the arena

Definition at line 110 of file task_arena.h.

Referenced by internal_attach(), internal_execute(), internal_initialize(), internal_terminate(), and internal_wait().

◆ my_master_slots

unsigned tbb::interface7::internal::task_arena_base::my_master_slots
protected

Reserved master slots.

Definition at line 117 of file task_arena.h.

Referenced by internal_attach(), and internal_initialize().

◆ my_max_concurrency

int tbb::interface7::internal::task_arena_base::my_max_concurrency
protected

Concurrency level for deferred initialization.

Definition at line 114 of file task_arena.h.

Referenced by internal_attach(), internal_initialize(), and internal_max_concurrency().

◆ my_version_and_traits

intptr_t tbb::interface7::internal::task_arena_base::my_version_and_traits
protected

Special settings.

Definition at line 120 of file task_arena.h.

Referenced by internal_attach(), internal_execute(), and internal_initialize().

◆ not_initialized

const int tbb::interface7::internal::task_arena_base::not_initialized = -2
static

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

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