Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb_main.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2020 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #ifndef _TBB_tbb_main_H
18 #define _TBB_tbb_main_H
19 
20 #include "tbb/atomic.h"
21 #include "governor.h"
22 #include "tbb_environment.h"
23 
24 namespace tbb {
25 
26 namespace internal {
27 
29 
30 //------------------------------------------------------------------------
31 // __TBB_InitOnce
32 //------------------------------------------------------------------------
33 
35 
38  friend void DoOneTimeInitializations();
40 
41  static atomic<int> count;
42 
44  static void acquire_resources();
45 
47  static void release_resources();
48 
50  static bool InitializationDone;
51 
53 
58 
59 public:
60  static void lock() { __TBB_LockByte( InitializationLock ); }
61 
63 
65 
67 
70 
72 
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  }
84  static void add_ref();
85 
87  static void remove_ref();
88 }; // class __TBB_InitOnce
89 
90 
91 } // namespace internal
92 
93 } // namespace tbb
94 
95 #endif /* _TBB_tbb_main_H */
#define __TBB_UnlockByte
Definition: gcc_generic.h:211
__TBB_atomic __TBB_Flag __TBB_atomic_flag
Definition: gcc_generic.h:106
__TBB_Flag __TBB_LockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:919
The graph class.
T __TBB_load_with_acquire(const volatile T &location)
Definition: tbb_machine.h:709
void DoOneTimeInitializations()
Performs thread-safe lazy one-time general TBB initialization.
Definition: tbb_main.cpp:215
static void terminate_auto_initialized_scheduler()
Undo automatic initialization if necessary; call when a thread exits.
Definition: governor.h:144
Class that supports TBB initialization.
Definition: tbb_main.h:37
static void release_resources()
Platform specific code to release resources.
__TBB_InitOnce()
Add initial reference to resources.
Definition: tbb_main.h:69
static bool initialization_done()
Definition: tbb_main.h:64
static bool InitializationDone
Specifies if the one-time initializations has been done.
Definition: tbb_main.h:50
static void acquire_resources()
Platform specific code to acquire resources.
friend void DoOneTimeInitializations()
Performs thread-safe lazy one-time general TBB initialization.
Definition: tbb_main.cpp:215
static void remove_ref()
Remove reference to resources. If last reference removed, release the resources.
Definition: tbb_main.cpp:122
friend void ITT_DoUnsafeOneTimeInitialization()
static atomic< int > count
Counter of references to global shared resources such as TLS.
Definition: tbb_main.h:41
static void add_ref()
Add reference to resources. If first reference added, acquire the resources.
Definition: tbb_main.cpp:117
~__TBB_InitOnce()
Remove the initial reference to resources.
Definition: tbb_main.h:73
static __TBB_atomic_flag InitializationLock
Global initialization lock.
Definition: tbb_main.h:57

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.