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

{ add_ref(); }

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.

{
governor::terminate_auto_initialized_scheduler(); // TLS dtor not called for the main thread
remove_ref();
// We assume that InitializationDone is not set after file-scope destructors
// start running, and thus no race on InitializationDone is possible.
if( initialization_done() ) {
// Remove an extra reference that was added in DoOneTimeInitializations.
remove_ref();
}
}

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 | ( |  | ) |

static private

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.

{
if( ++count==1 )
governor::acquire_resources();
}

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 | ( |  | ) |

inline static

Definition at line 64 of file tbb_main.h.

{ return __TBB_load_with_acquire(InitializationDone); }

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 | ( |  | ) |

inline static

Definition at line 60 of file tbb_main.h.

{ __TBB_LockByte( InitializationLock ); }

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 | ( |  | ) |

static private

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.

{
int k = --count;
__TBB_ASSERT(k>=0,"removed __TBB_InitOnce ref that was not added?");
if( k==0 ) {
governor::release_resources();
ITT_FINI_ITTLIB();
}
}

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 | ( |  | ) |

inline static

Definition at line 62 of file tbb_main.h.

{ __TBB_UnlockByte( InitializationLock ); }

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.

{
suppress_unused_warning(_pad);
__TBB_InitOnce::lock();
// No fence required for load of InitializationDone, because we are inside a critical section.
if( !__TBB_InitOnce::InitializationDone ) {
__TBB_InitOnce::add_ref();
if( GetBoolEnvironmentVariable("TBB_VERSION") )
PrintVersion();
bool itt_present = false;
#if DO_ITT_NOTIFY
ITT_DoUnsafeOneTimeInitialization();
itt_present = ITT_Present;
#endif /* DO_ITT_NOTIFY */
initialize_cache_aligned_allocator();
governor::initialize_rml_factory();
Scheduler_OneTimeInitialization( itt_present );
// Force processor groups support detection
governor::default_num_threads();
// Force OS regular page size detection
governor::default_page_size();
// Dump version data
governor::print_version_info();
PrintExtraVersionInfo( "Tools support", itt_present ? "enabled" : "disabled" );
__TBB_InitOnce::InitializationDone = true;
}
__TBB_InitOnce::unlock();
}

## ITT_DoUnsafeOneTimeInitialization

void ITT_DoUnsafeOneTimeInitialization | ( |  | ) |

friend

## Member Data Documentation

## count

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

static private

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

static private

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

static private

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:

- tbb_main.h
- tbb_main.cpp

tbb::internal::Scheduler_OneTimeInitialization
void Scheduler_OneTimeInitialization(bool itt_present)
Defined in scheduler.cpp.
Definition: scheduler.cpp:52
tbb::internal::__TBB_load_with_acquire
T __TBB_load_with_acquire(const volatile T &location)
Definition: tbb_machine.h:712
tbb::internal::__TBB_InitOnce::ITT_DoUnsafeOneTimeInitialization
friend void ITT_DoUnsafeOneTimeInitialization()
tbb::internal::__TBB_InitOnce::count
static atomic< int > count
Counter of references to global shared resources such as TLS.
Definition: tbb_main.h:41
tbb::internal::__TBB_InitOnce::add_ref
static void add_ref()
Add reference to resources. If first reference added, acquire the resources.
Definition: tbb_main.cpp:117
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
__TBB_LockByte
__TBB_Flag __TBB_LockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:922
tbb::internal::__TBB_InitOnce::initialization_done
static bool initialization_done()
Definition: tbb_main.h:64
tbb::internal::initialize_cache_aligned_allocator
void initialize_cache_aligned_allocator()
Defined in cache_aligned_allocator.cpp.
Definition: cache_aligned_allocator.cpp:132
tbb::internal::__TBB_InitOnce::unlock
static void unlock()
Definition: tbb_main.h:62
tbb::internal::governor::release_resources
static void release_resources()
Destroy the thread-local storage key and deinitialize RML.
Definition: governor.cpp:79
tbb::internal::governor::terminate_auto_initialized_scheduler
static void terminate_auto_initialized_scheduler()
Undo automatic initialization if necessary; call when a thread exits.
Definition: governor.h:144
tbb::internal::_pad
static const char _pad[NFS_MaxLineSize - sizeof(int)]
Padding in order to prevent false sharing.
Definition: tbb_main.cpp:34
tbb::internal::governor::initialize_rml_factory
static void initialize_rml_factory()
Definition: governor.cpp:242
tbb::internal::__TBB_InitOnce::InitializationLock
static __TBB_atomic_flag InitializationLock
Global initialization lock.
Definition: tbb_main.h:57
tbb::internal::governor::default_num_threads
static unsigned default_num_threads()
Definition: governor.h:84
tbb::internal::__TBB_InitOnce::remove_ref
static void remove_ref()
Remove reference to resources. If last reference removed, release the resources.
Definition: tbb_main.cpp:122
ITT_FINI_ITTLIB
#define ITT_FINI_ITTLIB()
Definition: itt_notify.h:114
tbb::internal::__TBB_InitOnce::lock
static void lock()
Definition: tbb_main.h:60
tbb::internal::PrintVersion
void PrintVersion()
Prints TBB version information on stderr.
Definition: tbb_misc.cpp:206
tbb::internal::governor::print_version_info
static void print_version_info()
Definition: governor.cpp:229
__TBB_UnlockByte
#define __TBB_UnlockByte
Definition: gcc_generic.h:211
tbb::internal::suppress_unused_warning
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:398
tbb::internal::governor::acquire_resources
static void acquire_resources()
Create key for thread-local storage and initialize RML.
Definition: governor.cpp:67
tbb::internal::governor::default_page_size
static size_t default_page_size()
Definition: governor.h:89
tbb::internal::PrintExtraVersionInfo
void PrintExtraVersionInfo(const char *category, const char *format,...)
Prints arbitrary extra TBB version information on stderr.
Definition: tbb_misc.cpp:211
tbb::internal::GetBoolEnvironmentVariable
static bool GetBoolEnvironmentVariable(const char *name)
Definition: tbb_environment.h:38
tbb::internal::__TBB_InitOnce::InitializationDone
static bool InitializationDone
Specifies if the one-time initializations has been done.
Definition: tbb_main.h:50

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.