tbb_main.h
Go to the documentation of this file.
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _TBB_tbb_main_H
#define _TBB_tbb_main_H
#include "tbb/atomic.h"
#include "governor.h"
#include "tbb_environment.h"
namespace tbb {
namespace internal {
void DoOneTimeInitializations ();
//------------------------------------------------------------------------
// __TBB_InitOnce
//------------------------------------------------------------------------
class __TBB_InitOnce {
friend void DoOneTimeInitializations();
friend void ITT_DoUnsafeOneTimeInitialization ();
static atomic<int> count;
static void acquire_resources();
static void release_resources();
static bool InitializationDone;
static __TBB_atomic_flag InitializationLock;
public:
static void lock() { __TBB_LockByte( InitializationLock ); }
static void unlock() { __TBB_UnlockByte( InitializationLock ); }
static bool initialization_done() { return __TBB_load_with_acquire(InitializationDone); }
__TBB_InitOnce() { add_ref(); }
~__TBB_InitOnce() {
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();
}
}
static void add_ref();
static void remove_ref();
}; // class __TBB_InitOnce
} // namespace internal
} // namespace tbb
#endif /* _TBB_tbb_main_H */
tbb::internal::__TBB_load_with_acquire
T __TBB_load_with_acquire(const volatile T &location)
Definition: tbb_machine.h:712
governor.h
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::internal::__TBB_InitOnce::~__TBB_InitOnce
~__TBB_InitOnce()
Remove the initial reference to resources.
Definition: tbb_main.h:73
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_LockByte
__TBB_Flag __TBB_LockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:922
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::internal::__TBB_InitOnce::initialization_done
static bool initialization_done()
Definition: tbb_main.h:64
tbb::internal::DoOneTimeInitializations
void DoOneTimeInitializations()
Performs thread-safe lazy one-time general TBB initialization.
Definition: tbb_main.cpp:215
tbb::internal::__TBB_InitOnce::release_resources
static void release_resources()
Platform specific code to release resources.
tbb::internal::__TBB_InitOnce::__TBB_InitOnce
__TBB_InitOnce()
Add initial reference to resources.
Definition: tbb_main.h:69
tbb::internal::__TBB_InitOnce
Class that supports TBB initialization.
Definition: tbb_main.h:37
tbb::internal::__TBB_InitOnce::unlock
static void unlock()
Definition: tbb_main.h:62
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::__TBB_InitOnce::InitializationLock
static __TBB_atomic_flag InitializationLock
Global initialization lock.
Definition: tbb_main.h:57
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
atomic.h
tbb::internal::__TBB_InitOnce::lock
static void lock()
Definition: tbb_main.h:60
__TBB_UnlockByte
#define __TBB_UnlockByte
Definition: gcc_generic.h:211
__TBB_atomic_flag
__TBB_atomic __TBB_Flag __TBB_atomic_flag
Definition: gcc_generic.h:106
tbb::internal::__TBB_InitOnce::DoOneTimeInitializations
friend void DoOneTimeInitializations()
Performs thread-safe lazy one-time general TBB initialization.
Definition: tbb_main.cpp:215
tbb::internal::__TBB_InitOnce::acquire_resources
static void acquire_resources()
Platform specific code to acquire resources.
tbb_environment.h
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.