diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2016-06-02 18:22:12 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2016-06-02 18:22:12 +0000 |
commit | dd1463823a0c79bb7a1382839bdedb28c5541b41 (patch) | |
tree | 61f489816f61f5fbe08858b3a49c3ff4a0190696 /llvm/lib/Support/ManagedStatic.cpp | |
parent | 90db78816b9cc285254b8a4d8fcf5c0499dc2dad (diff) | |
download | bcm5719-llvm-dd1463823a0c79bb7a1382839bdedb28c5541b41.tar.gz bcm5719-llvm-dd1463823a0c79bb7a1382839bdedb28c5541b41.zip |
This is yet another attempt to re-instate r220932 as discussed in
D19271.
Previous attempt was broken by NetBSD, so in this version I've made the
fallback path generic rather than Windows specific and sent both Windows
and NetBSD to it.
I've also re-formatted the code some, and used an exact clone of the
code in PassSupport.h for doing manual call-once using our atomics
rather than rolling a new one.
If this sticks, we can replace the fallback path for Windows with
a Windows-specific implementation that is more reliable.
Original commit message:
This patch adds an llvm_call_once which is a wrapper around
std::call_once on platforms where it is available and devoid
of bugs. The patch also migrates the ManagedStatic mutex to
be allocated using llvm_call_once.
These changes are philosophically equivalent to the changes
added in r219638, which were reverted due to a hang on Win32
which was the result of a bug in the Windows implementation
of std::call_once.
Differential Revision: http://reviews.llvm.org/D5922
llvm-svn: 271558
Diffstat (limited to 'llvm/lib/Support/ManagedStatic.cpp')
-rw-r--r-- | llvm/lib/Support/ManagedStatic.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/Support/ManagedStatic.cpp b/llvm/lib/Support/ManagedStatic.cpp index b8fb2841e52..b1feddc09ec 100644 --- a/llvm/lib/Support/ManagedStatic.cpp +++ b/llvm/lib/Support/ManagedStatic.cpp @@ -16,16 +16,23 @@ #include "llvm/Support/Atomic.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/MutexGuard.h" +#include "llvm/Support/Threading.h" #include <cassert> using namespace llvm; static const ManagedStaticBase *StaticList = nullptr; +static sys::Mutex *ManagedStaticMutex = nullptr; +LLVM_DEFINE_ONCE_FLAG(mutex_init_flag); -static sys::Mutex& getManagedStaticMutex() { +static void initializeMutex() { + ManagedStaticMutex = new sys::Mutex(); +} + +static sys::Mutex* getManagedStaticMutex() { // We need to use a function local static here, since this can get called // during a static constructor and we need to guarantee that it's initialized // correctly. - static sys::Mutex ManagedStaticMutex; + call_once(mutex_init_flag, initializeMutex); return ManagedStaticMutex; } @@ -33,7 +40,7 @@ void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(), void (*Deleter)(void*)) const { assert(Creator); if (llvm_is_multithreaded()) { - MutexGuard Lock(getManagedStaticMutex()); + MutexGuard Lock(*getManagedStaticMutex()); if (!Ptr) { void* tmp = Creator(); @@ -83,7 +90,7 @@ void ManagedStaticBase::destroy() const { /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables. void llvm::llvm_shutdown() { - MutexGuard Lock(getManagedStaticMutex()); + MutexGuard Lock(*getManagedStaticMutex()); while (StaticList) StaticList->destroy(); |