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
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
int max_concurrency()
Returns the maximal number of threads that can work inside the arena.
Definition: task_arena.h:412
unsigned my_master_slots
Reserved master slots.
Definition: task_arena.h:117
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106

Member Function Documentation

◆ internal_attach()

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

Definition at line 780 of file arena.cpp.

780  {
781  __TBB_ASSERT(!my_arena, NULL);
782  generic_scheduler* s = governor::local_scheduler_if_initialized();
783  if( s && s->my_arena ) {
784  // There is an active arena to attach to.
785  // It's still used by s, so won't be destroyed right away.
786  my_arena = s->my_arena;
787  __TBB_ASSERT( my_arena->my_references > 0, NULL );
788  my_arena->my_references += arena::ref_external;
789 #if __TBB_TASK_GROUP_CONTEXT
790  my_context = my_arena->my_default_ctx;
792 #endif
793  my_master_slots = my_arena->my_num_reserved_slots;
794  my_max_concurrency = my_master_slots + my_arena->my_max_num_workers;
796  // increases market's ref count for task_arena
797  market::global_market( /*is_public=*/true );
798  }
799 }
static int unsigned num_arena_slots(unsigned num_slots)
Definition: arena.h:199
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
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
intptr_t my_version_and_traits
Special settings.
Definition: task_arena.h:120
static generic_scheduler * local_scheduler_if_initialized()
Definition: governor.h:136
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:114
static const unsigned ref_external
Reference increment values for externals and workers.
Definition: arena.h:230
uintptr_t my_version_and_traits
Version for run-time checks and behavioral traits of the context.
Definition: task.h:423
unsigned my_master_slots
Reserved master slots.
Definition: task_arena.h:117
void const char const char int ITT_FORMAT __itt_group_sync s
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106

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

1015  {
1016  generic_scheduler* s = governor::local_scheduler_if_initialized();
1017  return s? int(s->my_arena_index) : -1;
1018 }
static generic_scheduler * local_scheduler_if_initialized()
Definition: governor.h:136
void const char const char int ITT_FORMAT __itt_group_sync s
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 801 of file arena.cpp.

801  {
802  __TBB_ASSERT(my_arena, NULL);
803  generic_scheduler* s = governor::local_scheduler_if_initialized();
804  __TBB_ASSERT(s, "Scheduler is not initialized"); // we allocated a task so can expect the scheduler
805 #if __TBB_TASK_GROUP_CONTEXT
806  __TBB_ASSERT(my_arena->my_default_ctx == t.prefix().context, NULL);
807  __TBB_ASSERT(!my_arena->my_default_ctx->is_group_execution_cancelled(), // TODO: any better idea?
808  "The task will not be executed because default task_group_context of task_arena is cancelled. Has previously enqueued task thrown an exception?");
809 #endif
810  my_arena->enqueue_task( t, prio, s->my_random );
811 }
#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
void const char const char int ITT_FORMAT __itt_group_sync s
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 862 of file arena.cpp.

862  {
863  __TBB_ASSERT(my_arena, NULL);
864  generic_scheduler* s = governor::local_scheduler_weak();
865  __TBB_ASSERT(s, "Scheduler is not initialized");
866 
867  bool same_arena = s->my_arena == my_arena;
868  size_t index1 = s->my_arena_index;
869  if (!same_arena) {
870  index1 = my_arena->occupy_free_slot</* as_worker*/false>(*s);
871  if (index1 == arena::out_of_arena) {
872 
873 #if __TBB_USE_OPTIONAL_RTTI
874  // Workaround for the bug inside graph. If the thread can not occupy arena slot during task_arena::execute()
875  // and all aggregator operations depend on this task completion (all other threads are inside arena already)
876  // deadlock appears, because enqueued task will never enter arena.
877  // Workaround: check if the task came from graph via RTTI (casting to graph::spawn_functor)
878  // and enqueue this task with non-blocking internal_enqueue method.
879  // TODO: have to change behaviour later in next GOLD release (maybe to add new library entry point - try_execute)
881  internal::delegated_function< graph_funct, void >* deleg_funct =
882  dynamic_cast< internal::delegated_function< graph_funct, void>* >(&d);
883 
884  if (deleg_funct) {
886  internal::function_task< internal::strip< graph_funct >::type >
887  (internal::forward< graph_funct >(deleg_funct->my_func)), 0);
888  return;
889  } else {
890 #endif /* __TBB_USE_OPTIONAL_RTTI */
891  concurrent_monitor::thread_context waiter;
892 #if __TBB_TASK_GROUP_CONTEXT
893  task_group_context exec_context(task_group_context::isolated, my_version_and_traits & exact_exception_flag);
894 #if __TBB_FP_CONTEXT
895  exec_context.copy_fp_settings(*my_context);
896 #endif
897 #endif
898  auto_empty_task root(__TBB_CONTEXT_ARG(s, &exec_context));
899  root.prefix().ref_count = 2;
900  my_arena->enqueue_task(*new(task::allocate_root(__TBB_CONTEXT_ARG1(exec_context)))
901  delegated_task(d, my_arena->my_exit_monitors, &root),
902  0, s->my_random); // TODO: priority?
903  size_t index2 = arena::out_of_arena;
904  do {
905  my_arena->my_exit_monitors.prepare_wait(waiter, (uintptr_t)&d);
906  if (__TBB_load_with_acquire(root.prefix().ref_count) < 2) {
907  my_arena->my_exit_monitors.cancel_wait(waiter);
908  break;
909  }
910  index2 = my_arena->occupy_free_slot</*as_worker*/false>(*s);
911  if (index2 != arena::out_of_arena) {
912  my_arena->my_exit_monitors.cancel_wait(waiter);
913  nested_arena_context scope(s, my_arena, index2, scheduler_properties::master, same_arena);
914  s->local_wait_for_all(root, NULL);
915 #if TBB_USE_EXCEPTIONS
916  __TBB_ASSERT(!exec_context.my_exception, NULL); // exception can be thrown above, not deferred
917 #endif
918  __TBB_ASSERT(root.prefix().ref_count == 0, NULL);
919  break;
920  }
921  my_arena->my_exit_monitors.commit_wait(waiter);
922  } while (__TBB_load_with_acquire(root.prefix().ref_count) == 2);
923  if (index2 == arena::out_of_arena) {
924  // notify a waiting thread even if this thread did not enter arena,
925  // in case it was woken by a leaving thread but did not need to enter
926  my_arena->my_exit_monitors.notify_one(); // do not relax!
927  }
928 #if TBB_USE_EXCEPTIONS
929  // process possible exception
930  if (task_group_context::exception_container_type *pe = exec_context.my_exception)
931  TbbRethrowException(pe);
932 #endif
933  return;
934 #if __TBB_USE_OPTIONAL_RTTI
935  } // if task came from graph
936 #endif
937  } // if (index1 == arena::out_of_arena)
938  } // if (!same_arena)
939 
940  context_guard_helper</*report_tasks=*/false> context_guard;
941  context_guard.set_ctx(__TBB_CONTEXT_ARG1(my_context));
942 #if TBB_USE_EXCEPTIONS
943  try {
944 #endif
945  //TODO: replace dummy tasks for workers as well to avoid using of the_dummy_context
946  nested_arena_context scope(s, my_arena, index1, scheduler_properties::master, same_arena);
947  d();
948 #if TBB_USE_EXCEPTIONS
949  }
950  catch (...) {
951  context_guard.restore_default(); // TODO: is it needed on Windows?
953  else {
954  task_group_context exception_container(task_group_context::isolated,
956  exception_container.register_pending_exception();
957  __TBB_ASSERT(exception_container.my_exception, NULL);
958  TbbRethrowException(exception_container.my_exception);
959  }
960  }
961 #endif
962 }
#define __TBB_CONTEXT_ARG(arg1, context)
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
T __TBB_load_with_acquire(const volatile T &location)
Definition: tbb_machine.h:713
#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
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
intptr_t my_version_and_traits
Special settings.
Definition: task_arena.h:120
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
internal::tbb_exception_ptr exception_container_type
Definition: task.h:344
void const char const char int ITT_FORMAT __itt_group_sync s
#define __TBB_CONTEXT_ARG1(context)
static generic_scheduler * local_scheduler_weak()
Definition: governor.h:131
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:636
void __TBB_EXPORTED_METHOD internal_enqueue(task &, intptr_t) const
Definition: arena.cpp:801

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

736  {
738  if( my_max_concurrency < 1 )
740  __TBB_ASSERT( my_master_slots <= (unsigned)my_max_concurrency, "Number of slots reserved for master should not exceed arena concurrency");
741  arena* new_arena = market::create_arena( my_max_concurrency, my_master_slots, 0 );
742  // add an internal market reference; a public reference was added in create_arena
743  market &m = market::global_market( /*is_public=*/false );
744  // allocate default context for task_arena
745 #if __TBB_TASK_GROUP_CONTEXT
746  new_arena->my_default_ctx = new ( NFS_Allocate(1, sizeof(task_group_context), NULL) )
748 #if __TBB_FP_CONTEXT
749  new_arena->my_default_ctx->capture_fp_settings();
750 #endif
751 #endif /* __TBB_TASK_GROUP_CONTEXT */
752  // threads might race to initialize the arena
753  if(as_atomic(my_arena).compare_and_swap(new_arena, NULL) != NULL) {
754  __TBB_ASSERT(my_arena, NULL); // another thread won the race
755  // release public market reference
756  m.release( /*is_public=*/true, /*blocking_terminate=*/false );
757  new_arena->on_thread_leaving<arena::ref_external>(); // destroy unneeded arena
758 #if __TBB_TASK_GROUP_CONTEXT
759  spin_wait_while_eq(my_context, (task_group_context*)NULL);
760  } else {
761  new_arena->my_default_ctx->my_version_and_traits |= my_version_and_traits & exact_exception_flag;
762  as_atomic(my_context) = new_arena->my_default_ctx;
763 #endif
764  }
765  // TODO: should it trigger automatic initialization of this thread?
767 }
void *__TBB_EXPORTED_FUNC NFS_Allocate(size_t n_element, size_t element_size, void *hint)
Allocate memory on cache/sector line boundary.
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
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 unsigned default_num_threads()
Definition: governor.h:85
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
static arena * create_arena(int num_slots, int num_reserved_slots, size_t stack_size)
Creates an arena object.
Definition: market.cpp:300
static const unsigned ref_external
Reference increment values for externals and workers.
Definition: arena.h:230
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
static void one_time_init()
Definition: governor.cpp:160
unsigned my_master_slots
Reserved master slots.
Definition: task_arena.h:117
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 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
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106
atomic< T > & as_atomic(T &t)
Definition: atomic.h:547

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

1046  {
1047  arena* a = NULL;
1048  if( ta ) // for special cases of ta->max_concurrency()
1049  a = ta->my_arena;
1050  else if( generic_scheduler* s = governor::local_scheduler_if_initialized() )
1051  a = s->my_arena; // the current arena if any
1052 
1053  if( a ) { // Get parameters from the arena
1054  __TBB_ASSERT( !ta || ta->my_max_concurrency==1, NULL );
1055  return a->my_num_reserved_slots + a->my_max_num_workers;
1056  } else {
1057  __TBB_ASSERT( !ta || ta->my_max_concurrency==automatic, NULL );
1059  }
1060 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
static unsigned default_num_threads()
Definition: governor.h:85
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 s
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 769 of file arena.cpp.

769  {
770  if( my_arena ) {// task_arena was initialized
771  my_arena->my_market->release( /*is_public=*/true, /*blocking_terminate=*/false );
772  my_arena->on_thread_leaving<arena::ref_external>();
773  my_arena = 0;
774 #if __TBB_TASK_GROUP_CONTEXT
775  my_context = 0;
776 #endif
777  }
778 }
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:230
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 986 of file arena.cpp.

986  {
987  __TBB_ASSERT(my_arena, NULL);
988  generic_scheduler* s = governor::local_scheduler_weak();
989  __TBB_ASSERT(s, "Scheduler is not initialized");
990  __TBB_ASSERT(s->my_arena != my_arena || s->my_arena_index == 0, "task_arena::wait_until_empty() is not supported within a worker context" );
991  if( s->my_arena == my_arena ) {
992  //unsupported, but try do something for outermost master
993  __TBB_ASSERT(s->master_outermost_level(), "unsupported");
994  if( !s->my_arena_index )
995  while( my_arena->num_workers_active() )
996  s->wait_until_empty();
997  } else for(;;) {
998  while( my_arena->my_pool_state != arena::SNAPSHOT_EMPTY ) {
999  if( !__TBB_load_with_acquire(my_arena->my_slots[0].my_scheduler) // TODO TEMP: one master, make more masters
1000  && as_atomic(my_arena->my_slots[0].my_scheduler).compare_and_swap(s, NULL) == NULL ) {
1001  nested_arena_context a(s, my_arena, 0, scheduler_properties::worker, false);
1002  s->wait_until_empty();
1003  } else {
1004  binary_semaphore waiter; // TODO: replace by a single event notification from is_out_of_work
1005  internal_enqueue( *new( task::allocate_root(__TBB_CONTEXT_ARG1(*my_context)) ) wait_task(waiter), 0 ); // TODO: priority?
1006  waiter.P(); // TODO: concurrent_monitor
1007  }
1008  }
1009  if( !my_arena->num_workers_active() && !my_arena->my_slots[0].my_scheduler) // no activity
1010  break; // spin until workers active but avoid spinning in a worker
1011  __TBB_Yield(); // wait until workers and master leave
1012  }
1013 }
task_group_context * my_context
default context of the arena
Definition: task_arena.h:110
T __TBB_load_with_acquire(const volatile T &location)
Definition: tbb_machine.h:713
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
#define __TBB_Yield()
Definition: ibm_aix51.h:48
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 s
#define __TBB_CONTEXT_ARG1(context)
static generic_scheduler * local_scheduler_weak()
Definition: governor.h:131
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:106
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:636
atomic< T > & as_atomic(T &t)
Definition: atomic.h:547
void __TBB_EXPORTED_METHOD internal_enqueue(task &, intptr_t) const
Definition: arena.cpp:801

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