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

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
default_flags 
exact_exception_flag 

Definition at line 118 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 126 of file task_arena.h.

References __TBB_EXPORTED_FUNC, and __TBB_EXPORTED_METHOD.

127  : my_arena(0)
128 #if __TBB_TASK_GROUP_CONTEXT
129  , my_context(0)
130 #endif
132  , my_master_slots(reserved_for_masters)
134  {}
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:102
task_group_context * my_context
default context of the arena
Definition: task_arena.h:106
int max_concurrency()
Returns the maximal number of threads that can work inside the arena.
Definition: task_arena.h:413
unsigned my_master_slots
Reserved master slots.
Definition: task_arena.h:113
intptr_t my_version_and_traits
Special settings.
Definition: task_arena.h:116
int my_max_concurrency
Concurrency level for deferred initialization.
Definition: task_arena.h:110

Member Function Documentation

◆ internal_attach()

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

Definition at line 776 of file arena.cpp.

References __TBB_ASSERT, tbb::internal::market::global_market(), tbb::internal::governor::local_scheduler_if_initialized(), tbb::internal::scheduler_state::my_arena, 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, tbb::internal::arena::num_arena_slots(), tbb::internal::arena::ref_external, and s.

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

References __TBB_ASSERT, __TBB_ASSERT_EX, d, int, tbb::interface7::internal::isolate_within_arena(), tbb::internal::governor::local_scheduler_if_initialized(), tbb::internal::governor::local_scheduler_weak(), tbb::internal::scheduler_state::my_arena_index, tbb::internal::scheduler_state::my_innermost_running_task, tbb::task::prefix(), and s.

1011  {
1012  generic_scheduler* s = governor::local_scheduler_if_initialized();
1013  return s? int(s->my_arena_index) : -1;
1014 }
void const char const char int ITT_FORMAT __itt_group_sync s
static generic_scheduler * local_scheduler_if_initialized()
Definition: governor.h:132
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
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 797 of file arena.cpp.

References __TBB_ASSERT, tbb::internal::arena::enqueue_task(), tbb::internal::governor::local_scheduler_if_initialized(), tbb::internal::scheduler_state::my_arena, tbb::internal::generic_scheduler::my_random, tbb::task::prefix(), and s.

797  {
798  __TBB_ASSERT(my_arena, NULL);
799  generic_scheduler* s = governor::local_scheduler_if_initialized();
800  __TBB_ASSERT(s, "Scheduler is not initialized"); // we allocated a task so can expect the scheduler
801 #if __TBB_TASK_GROUP_CONTEXT
802  // Is there a better place for checking the state of my_default_ctx?
803  __TBB_ASSERT(!(my_arena->my_default_ctx == t.prefix().context && my_arena->my_default_ctx->is_group_execution_cancelled()),
804  "The task will not be executed because default task_group_context of task_arena is cancelled. Has previously enqueued task thrown an exception?");
805 #endif
806  my_arena->enqueue_task( t, prio, s->my_random );
807 }
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:102
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:165
static generic_scheduler * local_scheduler_if_initialized()
Definition: governor.h:132
Here is the call graph for this function:

◆ internal_execute()

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

Definition at line 858 of file arena.cpp.

References __TBB_ASSERT, __TBB_CONTEXT_ARG, __TBB_CONTEXT_ARG1, tbb::internal::__TBB_load_with_acquire(), tbb::task::allocate_root(), tbb::internal::concurrent_monitor::cancel_wait(), tbb::internal::concurrent_monitor::commit_wait(), tbb::task_group_context::copy_fp_settings(), d, tbb::task_group_context::default_traits, tbb::internal::arena::enqueue_task(), tbb::task_group_context::exact_exception, tbb::task_group_context::isolated, tbb::internal::governor::local_scheduler_weak(), tbb::internal::generic_scheduler::local_wait_for_all(), tbb::internal::scheduler_properties::master, tbb::internal::scheduler_state::my_arena, tbb::internal::scheduler_state::my_arena_index, tbb::task_group_context::my_exception, tbb::internal::arena_base::my_exit_monitors, tbb::internal::generic_scheduler::my_random, tbb::internal::concurrent_monitor::notify_one(), tbb::internal::arena::occupy_free_slot(), tbb::internal::arena::out_of_arena, tbb::internal::auto_empty_task::prefix(), tbb::internal::concurrent_monitor::prepare_wait(), 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().

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

◆ internal_initialize()

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

Definition at line 732 of file arena.cpp.

References __TBB_ASSERT, tbb::internal::as_atomic(), tbb::internal::market::create_arena(), tbb::internal::governor::default_num_threads(), tbb::task_group_context::default_traits, tbb::internal::market::global_market(), int, tbb::task_group_context::isolated, tbb::internal::governor::local_scheduler_weak(), tbb::internal::scheduler_state::my_arena, 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().

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

References __TBB_ASSERT, 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().

1042  {
1043  arena* a = NULL;
1044  if( ta ) // for special cases of ta->max_concurrency()
1045  a = ta->my_arena;
1046  else if( generic_scheduler* s = governor::local_scheduler_if_initialized() )
1047  a = s->my_arena; // the current arena if any
1048 
1049  if( a ) { // Get parameters from the arena
1050  __TBB_ASSERT( !ta || ta->my_max_concurrency==1, NULL );
1051  return a->my_num_reserved_slots + a->my_max_num_workers;
1052  } else {
1053  __TBB_ASSERT( !ta || ta->my_max_concurrency==automatic, NULL );
1055  }
1056 }
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:165
static generic_scheduler * local_scheduler_if_initialized()
Definition: governor.h:132
static const int automatic
Typedef for number of threads that is automatic.
Definition: task_arena.h:146
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 unsigned default_num_threads()
Definition: governor.h:81
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 765 of file arena.cpp.

References tbb::internal::scheduler_state::my_arena, tbb::internal::arena_base::my_market, tbb::internal::arena::on_thread_leaving(), tbb::internal::arena::ref_external, and tbb::internal::market::release().

765  {
766  if( my_arena ) {// task_arena was initialized
767  my_arena->my_market->release( /*is_public=*/true, /*blocking_terminate=*/false );
768  my_arena->on_thread_leaving<arena::ref_external>();
769  my_arena = 0;
770 #if __TBB_TASK_GROUP_CONTEXT
771  my_context = 0;
772 #endif
773  }
774 }
static const unsigned ref_external
Reference increment values for externals and workers.
Definition: arena.h:226
internal::arena * my_arena
NULL if not currently initialized.
Definition: task_arena.h:102
task_group_context * my_context
default context of the arena
Definition: task_arena.h:106
Here is the call graph for this function:

◆ internal_wait()

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

Definition at line 982 of file arena.cpp.

References __TBB_ASSERT, __TBB_CONTEXT_ARG1, tbb::internal::__TBB_load_with_acquire(), __TBB_Yield, tbb::task::allocate_root(), tbb::internal::as_atomic(), tbb::internal::governor::local_scheduler_weak(), tbb::internal::generic_scheduler::master_outermost_level(), tbb::internal::scheduler_state::my_arena, tbb::internal::scheduler_state::my_arena_index, tbb::internal::arena_base::my_pool_state, tbb::internal::arena_slot_line1::my_scheduler, tbb::internal::arena::my_slots, tbb::internal::arena::num_workers_active(), tbb::internal::binary_semaphore::P(), s, tbb::internal::arena::SNAPSHOT_EMPTY, tbb::internal::generic_scheduler::wait_until_empty(), and tbb::internal::scheduler_properties::worker.

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

◆ my_arena

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

NULL if not currently initialized.

Definition at line 102 of file task_arena.h.

Referenced by internal_max_concurrency().

◆ my_context

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

default context of the arena

Definition at line 106 of file task_arena.h.

◆ my_master_slots

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

Reserved master slots.

Definition at line 113 of file task_arena.h.

◆ my_max_concurrency

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

Concurrency level for deferred initialization.

Definition at line 110 of file task_arena.h.

Referenced by 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 116 of file task_arena.h.

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