Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::internal::__TBB_InitOnce Class Reference

Class that supports TBB initialization. More...

#include <tbb_main.h>

Collaboration diagram for tbb::internal::__TBB_InitOnce:

Public Member Functions

 __TBB_InitOnce ()
 Add initial reference to resources. More...
 
 ~__TBB_InitOnce ()
 Remove the initial reference to resources. More...
 

Static Public Member Functions

static void lock ()
 
static void unlock ()
 
static bool initialization_done ()
 
static void add_ref ()
 Add reference to resources. If first reference added, acquire the resources. More...
 
static void remove_ref ()
 Remove reference to resources. If last reference removed, release the resources. More...
 

Static Private Member Functions

static void acquire_resources ()
 Platform specific code to acquire resources. More...
 
static void release_resources ()
 Platform specific code to release resources. More...
 

Static Private Attributes

static atomic< intcount
 Counter of references to global shared resources such as TLS. More...
 
static bool InitializationDone
 Specifies if the one-time initializations has been done. More...
 
static __TBB_atomic_flag InitializationLock
 Global initialization lock. More...
 

Friends

void DoOneTimeInitializations ()
 Performs thread-safe lazy one-time general TBB initialization. More...
 
void ITT_DoUnsafeOneTimeInitialization ()
 

Detailed Description

Class that supports TBB initialization.

It handles acquisition and release of global resources (e.g. TLS) during startup and shutdown, as well as synchronization for DoOneTimeInitializations.

Definition at line 37 of file tbb_main.h.

Constructor & Destructor Documentation

◆ __TBB_InitOnce()

tbb::internal::__TBB_InitOnce::__TBB_InitOnce ( )
inline

Add initial reference to resources.

We assume that dynamic loading of the library prevents any other threads from entering the library until this constructor has finished running.

Definition at line 69 of file tbb_main.h.

69 { add_ref(); }
static void add_ref()
Add reference to resources. If first reference added, acquire the resources.
Definition: tbb_main.cpp:117

References add_ref().

Here is the call graph for this function:

◆ ~__TBB_InitOnce()

tbb::internal::__TBB_InitOnce::~__TBB_InitOnce ( )
inline

Remove the initial reference to resources.

This is not necessarily the last reference if other threads are still running.

Definition at line 73 of file tbb_main.h.

73  {
74  governor::terminate_auto_initialized_scheduler(); // TLS dtor not called for the main thread
75  remove_ref();
76  // We assume that InitializationDone is not set after file-scope destructors
77  // start running, and thus no race on InitializationDone is possible.
78  if( initialization_done() ) {
79  // Remove an extra reference that was added in DoOneTimeInitializations.
80  remove_ref();
81  }
82  }
static void terminate_auto_initialized_scheduler()
Undo automatic initialization if necessary; call when a thread exits.
Definition: governor.h:144
static bool initialization_done()
Definition: tbb_main.h:64
static void remove_ref()
Remove reference to resources. If last reference removed, release the resources.
Definition: tbb_main.cpp:122

References initialization_done(), remove_ref(), and tbb::internal::governor::terminate_auto_initialized_scheduler().

Here is the call graph for this function:

Member Function Documentation

◆ acquire_resources()

static void tbb::internal::__TBB_InitOnce::acquire_resources ( )
staticprivate

Platform specific code to acquire resources.

◆ add_ref()

void tbb::internal::__TBB_InitOnce::add_ref ( )
static

Add reference to resources. If first reference added, acquire the resources.

Definition at line 117 of file tbb_main.cpp.

117  {
118  if( ++count==1 )
120 }
static atomic< int > count
Counter of references to global shared resources such as TLS.
Definition: tbb_main.h:41
static void acquire_resources()
Create key for thread-local storage and initialize RML.
Definition: governor.cpp:67

References tbb::internal::governor::acquire_resources(), and count.

Referenced by __TBB_InitOnce(), tbb::internal::DoOneTimeInitializations(), and tbb::internal::market::global_market().

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

◆ initialization_done()

static bool tbb::internal::__TBB_InitOnce::initialization_done ( )
inlinestatic

Definition at line 64 of file tbb_main.h.

static bool InitializationDone
Specifies if the one-time initializations has been done.
Definition: tbb_main.h:50
T __TBB_load_with_acquire(const volatile T &location)
Definition: tbb_machine.h:709

References tbb::internal::__TBB_load_with_acquire(), and InitializationDone.

Referenced by tbb::internal::governor::one_time_init(), tbb::internal::governor::release_resources(), and ~__TBB_InitOnce().

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

◆ lock()

static void tbb::internal::__TBB_InitOnce::lock ( )
inlinestatic

Definition at line 60 of file tbb_main.h.

__TBB_Flag __TBB_LockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:919
static __TBB_atomic_flag InitializationLock
Global initialization lock.
Definition: tbb_main.h:57

References __TBB_LockByte(), and InitializationLock.

Referenced by tbb::internal::DoOneTimeInitializations().

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

◆ release_resources()

static void tbb::internal::__TBB_InitOnce::release_resources ( )
staticprivate

Platform specific code to release resources.

◆ remove_ref()

void tbb::internal::__TBB_InitOnce::remove_ref ( )
static

Remove reference to resources. If last reference removed, release the resources.

Definition at line 122 of file tbb_main.cpp.

122  {
123  int k = --count;
124  __TBB_ASSERT(k>=0,"removed __TBB_InitOnce ref that was not added?");
125  if( k==0 ) {
127  ITT_FINI_ITTLIB();
128  }
129 }
static atomic< int > count
Counter of references to global shared resources such as TLS.
Definition: tbb_main.h:41
static void release_resources()
Destroy the thread-local storage key and deinitialize RML.
Definition: governor.cpp:79
#define ITT_FINI_ITTLIB()
Definition: itt_notify.h:114
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

References __TBB_ASSERT, count, ITT_FINI_ITTLIB, and tbb::internal::governor::release_resources().

Referenced by tbb::internal::market::destroy(), and ~__TBB_InitOnce().

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

◆ unlock()

static void tbb::internal::__TBB_InitOnce::unlock ( )
inlinestatic

Definition at line 62 of file tbb_main.h.

#define __TBB_UnlockByte
Definition: gcc_generic.h:211
static __TBB_atomic_flag InitializationLock
Global initialization lock.
Definition: tbb_main.h:57

References __TBB_UnlockByte, and InitializationLock.

Referenced by tbb::internal::DoOneTimeInitializations().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ DoOneTimeInitializations

void DoOneTimeInitializations ( )
friend

Performs thread-safe lazy one-time general TBB initialization.

Definition at line 215 of file tbb_main.cpp.

215  {
218  // No fence required for load of InitializationDone, because we are inside a critical section.
221  if( GetBoolEnvironmentVariable("TBB_VERSION") )
222  PrintVersion();
223  bool itt_present = false;
224 #if DO_ITT_NOTIFY
226  itt_present = ITT_Present;
227 #endif /* DO_ITT_NOTIFY */
230  Scheduler_OneTimeInitialization( itt_present );
231  // Force processor groups support detection
233  // Force OS regular page size detection
235  // Dump version data
237  PrintExtraVersionInfo( "Tools support", itt_present ? "enabled" : "disabled" );
239  }
241 }
friend void ITT_DoUnsafeOneTimeInitialization()
static unsigned default_num_threads()
Definition: governor.h:84
void PrintVersion()
Prints TBB version information on stderr.
Definition: tbb_misc.cpp:206
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:398
static void print_version_info()
Definition: governor.cpp:229
static void add_ref()
Add reference to resources. If first reference added, acquire the resources.
Definition: tbb_main.cpp:117
static bool GetBoolEnvironmentVariable(const char *name)
static void initialize_rml_factory()
Definition: governor.cpp:242
static bool InitializationDone
Specifies if the one-time initializations has been done.
Definition: tbb_main.h:50
void initialize_cache_aligned_allocator()
Defined in cache_aligned_allocator.cpp.
static size_t default_page_size()
Definition: governor.h:89
static const char _pad[NFS_MaxLineSize - sizeof(int)]
Padding in order to prevent false sharing.
Definition: tbb_main.cpp:34
void Scheduler_OneTimeInitialization(bool itt_present)
Defined in scheduler.cpp.
Definition: scheduler.cpp:52
void PrintExtraVersionInfo(const char *category, const char *format,...)
Prints arbitrary extra TBB version information on stderr.
Definition: tbb_misc.cpp:211

◆ ITT_DoUnsafeOneTimeInitialization

void ITT_DoUnsafeOneTimeInitialization ( )
friend

Member Data Documentation

◆ count

atomic< int > tbb::internal::__TBB_InitOnce::count
staticprivate

Counter of references to global shared resources such as TLS.

Definition at line 41 of file tbb_main.h.

Referenced by add_ref(), and remove_ref().

◆ InitializationDone

bool tbb::internal::__TBB_InitOnce::InitializationDone
staticprivate

Specifies if the one-time initializations has been done.

Flag that is set to true after one-time initializations are done.

Definition at line 50 of file tbb_main.h.

Referenced by tbb::internal::DoOneTimeInitializations(), and initialization_done().

◆ InitializationLock

__TBB_atomic_flag tbb::internal::__TBB_InitOnce::InitializationLock
staticprivate

Global initialization lock.

Scenarios are possible when tools interop has to be initialized before the TBB itself. This imposes a requirement that the global initialization lock has to support valid static initialization, and does not issue any tool notifications in any build mode.

Definition at line 57 of file tbb_main.h.

Referenced by lock(), and unlock().


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

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