Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::interface9::global_control Class Reference

#include <global_control.h>

Collaboration diagram for tbb::interface9::global_control:

Public Types

enum  parameter { max_allowed_parallelism, thread_stack_size, parameter_max }
 

Public Member Functions

 global_control (parameter p, size_t value)
 
 ~global_control ()
 

Static Public Member Functions

static size_t active_value (parameter p)
 

Private Member Functions

void __TBB_EXPORTED_METHOD internal_create ()
 
void __TBB_EXPORTED_METHOD internal_destroy ()
 

Static Private Member Functions

static size_t __TBB_EXPORTED_FUNC active_value (int param)
 

Private Attributes

size_t my_value
 
global_controlmy_next
 
parameter my_param
 

Detailed Description

Definition at line 29 of file global_control.h.

Member Enumeration Documentation

◆ parameter

Enumerator
max_allowed_parallelism 
thread_stack_size 
parameter_max 

Definition at line 31 of file global_control.h.

Constructor & Destructor Documentation

◆ global_control()

tbb::interface9::global_control::global_control ( parameter  p,
size_t  value 
)
inline

Definition at line 37 of file global_control.h.

References __TBB_ASSERT, __TBB_ASSERT_RELEASE, internal_create(), max_allowed_parallelism, my_param, my_value, parameter_max, and thread_stack_size.

37  :
38  my_value(value), my_next(NULL), my_param(p) {
39  __TBB_ASSERT(my_param < parameter_max, "Invalid parameter");
40 #if __TBB_WIN8UI_SUPPORT
41  // For Windows Store* apps it's impossible to set stack size
42  if (p==thread_stack_size)
43  return;
44 #elif __TBB_x86_64 && (_WIN32 || _WIN64)
45  if (p==thread_stack_size)
46  __TBB_ASSERT_RELEASE((unsigned)value == value, "Stack size is limited to unsigned int range");
47 #endif
49  __TBB_ASSERT_RELEASE(my_value>0, "max_allowed_parallelism cannot be 0.");
51  }
#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 p
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 value
void __TBB_EXPORTED_METHOD internal_create()
Definition: tbb_main.cpp:503
#define __TBB_ASSERT_RELEASE(predicate, message)
Definition: tbb_stddef.h:138
Here is the call graph for this function:

◆ ~global_control()

tbb::interface9::global_control::~global_control ( )
inline

Definition at line 53 of file global_control.h.

References __TBB_ASSERT, internal_destroy(), my_param, parameter_max, and thread_stack_size.

53  {
54  __TBB_ASSERT(my_param < parameter_max, "Invalid parameter. Probably the object was corrupted.");
55 #if __TBB_WIN8UI_SUPPORT
56  // For Windows Store* apps it's impossible to set stack size
58  return;
59 #endif
61  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
void __TBB_EXPORTED_METHOD internal_destroy()
Definition: tbb_main.cpp:519
Here is the call graph for this function:

Member Function Documentation

◆ active_value() [1/2]

static size_t tbb::interface9::global_control::active_value ( parameter  p)
inlinestatic

Definition at line 63 of file global_control.h.

References __TBB_ASSERT, and parameter_max.

Referenced by tbb::internal::market::global_market(), and tbb::internal::tbb_thread_v3::internal_start().

63  {
64  __TBB_ASSERT(p < parameter_max, "Invalid parameter");
65  return active_value((int)p);
66  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
static size_t active_value(parameter p)
void const char const char int ITT_FORMAT __itt_group_sync p
Here is the caller graph for this function:

◆ active_value() [2/2]

size_t tbb::interface9::global_control::active_value ( int  param)
staticprivate

Definition at line 559 of file tbb_main.cpp.

References __TBB_ASSERT_RELEASE, tbb::internal::control_storage::active_value(), tbb::internal::controls, and parameter_max.

559  {
561  return controls[param]->active_value();
562 }
static control_storage * controls[]
Definition: tbb_main.cpp:490
virtual size_t active_value() const
Definition: tbb_main.cpp:441
#define __TBB_ASSERT_RELEASE(predicate, message)
Definition: tbb_stddef.h:138
Here is the call graph for this function:

◆ internal_create()

void tbb::interface9::global_control::internal_create ( )
private

Definition at line 503 of file tbb_main.cpp.

References __TBB_ASSERT_RELEASE, tbb::internal::control_storage::apply_active(), tbb::internal::controls, tbb::internal::control_storage::is_first_arg_preferred(), tbb::internal::__TBB_InitOnce::lock(), tbb::internal::control_storage::my_active_value, tbb::internal::control_storage::my_head, tbb::internal::control_storage::my_list_mutex, and parameter_max.

Referenced by global_control().

503  {
505  control_storage *const c = controls[my_param];
506 
510  // to guarantee that apply_active() is called with current active value,
511  // calls it here and in internal_destroy() under my_list_mutex
512  c->apply_active();
513  }
514  my_next = c->my_head;
515  // publish my_head, at this point my_active_value must be valid
516  c->my_head = this;
517 }
atomic< global_control * > my_head
Definition: tbb_main.cpp:433
static control_storage * controls[]
Definition: tbb_main.cpp:490
virtual void apply_active() const
Definition: tbb_main.cpp:437
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 * lock
friend class scoped_lock
Definition: spin_mutex.h:180
virtual bool is_first_arg_preferred(size_t a, size_t b) const
Definition: tbb_main.cpp:438
#define __TBB_ASSERT_RELEASE(predicate, message)
Definition: tbb_stddef.h:138
Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_destroy()

void tbb::interface9::global_control::internal_destroy ( )
private

Definition at line 519 of file tbb_main.cpp.

References __TBB_ASSERT, __TBB_ASSERT_RELEASE, tbb::internal::control_storage::apply_active(), tbb::internal::controls, tbb::internal::control_storage::default_value(), tbb::internal::control_storage::is_first_arg_preferred(), tbb::internal::__TBB_InitOnce::lock(), tbb::internal::control_storage::my_active_value, tbb::internal::control_storage::my_head, tbb::internal::control_storage::my_list_mutex, my_next, and parameter_max.

Referenced by ~global_control().

519  {
520  global_control *prev = 0;
521 
523  control_storage *const c = controls[my_param];
524  __TBB_ASSERT( c->my_head, NULL );
525 
526  // Concurrent reading and changing global parameter is possible.
527  // In this case, my_active_value may not match current state of parameters.
528  // This is OK because:
529  // 1) my_active_value is either current or previous
530  // 2) my_active_value is current on internal_destroy leave
532  size_t new_active = (size_t)-1, old_active = c->my_active_value;
533 
534  if ( c->my_head != this )
535  new_active = c->my_head->my_value;
536  else if ( c->my_head->my_next )
537  new_active = c->my_head->my_next->my_value;
538  // if there is only one element, new_active will be set later
539  for ( global_control *curr = c->my_head; curr; prev = curr, curr = curr->my_next )
540  if ( curr == this ) {
541  if ( prev )
542  prev->my_next = my_next;
543  else
544  c->my_head = my_next;
545  } else
546  if (c->is_first_arg_preferred(curr->my_value, new_active))
547  new_active = curr->my_value;
548 
549  if ( !c->my_head ) {
550  __TBB_ASSERT( new_active==(size_t)-1, NULL );
551  new_active = c->default_value();
552  }
553  if ( new_active != old_active ) {
554  c->my_active_value = new_active;
555  c->apply_active();
556  }
557 }
atomic< global_control * > my_head
Definition: tbb_main.cpp:433
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
static control_storage * controls[]
Definition: tbb_main.cpp:490
virtual void apply_active() const
Definition: tbb_main.cpp:437
global_control(parameter p, size_t value)
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 * lock
friend class scoped_lock
Definition: spin_mutex.h:180
virtual bool is_first_arg_preferred(size_t a, size_t b) const
Definition: tbb_main.cpp:438
#define __TBB_ASSERT_RELEASE(predicate, message)
Definition: tbb_stddef.h:138
virtual size_t default_value() const =0
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ my_next

global_control* tbb::interface9::global_control::my_next
private

Definition at line 69 of file global_control.h.

Referenced by internal_destroy().

◆ my_param

parameter tbb::interface9::global_control::my_param
private

Definition at line 70 of file global_control.h.

Referenced by global_control(), and ~global_control().

◆ my_value

size_t tbb::interface9::global_control::my_value
private

Definition at line 68 of file global_control.h.

Referenced by global_control().


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.