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-2019 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 
18 
19 */
20 
21 #ifndef _TBB_tbb_main_H
22 #define _TBB_tbb_main_H
23 
24 #include "tbb/atomic.h"
25 #include "governor.h"
26 #include "tbb_environment.h"
27 
28 namespace tbb {
29 
30 namespace internal {
31 
33 
34 //------------------------------------------------------------------------
35 // __TBB_InitOnce
36 //------------------------------------------------------------------------
37 
39 
42  friend void DoOneTimeInitializations();
43  friend void ITT_DoUnsafeOneTimeInitialization ();
44 
46 
48  static void acquire_resources();
49 
51  static void release_resources();
52 
54  static bool InitializationDone;
55 
57 
62 
63 public:
64  static void lock() { __TBB_LockByte( InitializationLock ); }
65 
67 
69 
71 
74 
76 
78  governor::terminate_auto_initialized_scheduler(); // TLS dtor not called for the main thread
79  remove_ref();
80  // We assume that InitializationDone is not set after file-scope destructors
81  // start running, and thus no race on InitializationDone is possible.
82  if( initialization_done() ) {
83  // Remove an extra reference that was added in DoOneTimeInitializations.
84  remove_ref();
85  }
86  }
88  static void add_ref();
89 
91  static void remove_ref();
92 }; // class __TBB_InitOnce
93 
94 
95 } // namespace internal
96 
97 } // namespace tbb
98 
99 #endif /* _TBB_tbb_main_H */
#define __TBB_UnlockByte
Definition: gcc_generic.h:215
friend void DoOneTimeInitializations()
Performs thread-safe lazy one-time general TBB initialization.
Definition: tbb_main.cpp:218
static void release_resources()
Platform specific code to release resources.
__TBB_atomic __TBB_Flag __TBB_atomic_flag
Definition: gcc_generic.h:110
static void terminate_auto_initialized_scheduler()
Undo automatic initialization if necessary; call when a thread exits.
Definition: governor.h:141
static bool InitializationDone
Specifies if the one-time initializations has been done.
Definition: tbb_main.h:54
Class that supports TBB initialization.
Definition: tbb_main.h:41
T __TBB_load_with_acquire(const volatile T &location)
Definition: tbb_machine.h:713
static atomic< int > count
Counter of references to global shared resources such as TLS.
Definition: tbb_main.h:45
static __TBB_atomic_flag InitializationLock
Global initialization lock.
Definition: tbb_main.h:61
static void add_ref()
Add reference to resources. If first reference added, acquire the resources.
Definition: tbb_main.cpp:120
static void acquire_resources()
Platform specific code to acquire resources.
static bool initialization_done()
Definition: tbb_main.h:68
static void remove_ref()
Remove reference to resources. If last reference removed, release the resources.
Definition: tbb_main.cpp:125
The graph class.
friend void ITT_DoUnsafeOneTimeInitialization()
void DoOneTimeInitializations()
Performs thread-safe lazy one-time general TBB initialization.
Definition: tbb_main.cpp:218
~__TBB_InitOnce()
Remove the initial reference to resources.
Definition: tbb_main.h:77
__TBB_Flag __TBB_LockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:923
__TBB_InitOnce()
Add initial reference to resources.
Definition: tbb_main.h:73

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.