diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-08-22 19:00:43 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2021-11-13 20:39:49 +0000 |
commit | fe6060f10f634930ff71b7c50291ddc610da2475 (patch) | |
tree | 1483580c790bd4d27b6500a7542b5ee00534d3cc /contrib/llvm-project/llvm/lib/Support/ManagedStatic.cpp | |
parent | b61bce17f346d79cecfd8f195a64b10f77be43b1 (diff) | |
parent | 344a3780b2e33f6ca763666c380202b18aab72a3 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/ManagedStatic.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Support/ManagedStatic.cpp | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/ManagedStatic.cpp b/contrib/llvm-project/llvm/lib/Support/ManagedStatic.cpp index 053493f72fb5..a6ae67066ea0 100644 --- a/contrib/llvm-project/llvm/lib/Support/ManagedStatic.cpp +++ b/contrib/llvm-project/llvm/lib/Support/ManagedStatic.cpp @@ -18,16 +18,10 @@ using namespace llvm; static const ManagedStaticBase *StaticList = nullptr; -static std::recursive_mutex *ManagedStaticMutex = nullptr; -static llvm::once_flag mutex_init_flag; - -static void initializeMutex() { - ManagedStaticMutex = new std::recursive_mutex(); -} static std::recursive_mutex *getManagedStaticMutex() { - llvm::call_once(mutex_init_flag, initializeMutex); - return ManagedStaticMutex; + static std::recursive_mutex m; + return &m; } void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(), @@ -75,9 +69,10 @@ void ManagedStaticBase::destroy() const { } /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables. +/// IMPORTANT: it's only safe to call llvm_shutdown() in single thread, +/// without any other threads executing LLVM APIs. +/// llvm_shutdown() should be the last use of LLVM APIs. void llvm::llvm_shutdown() { - std::lock_guard<std::recursive_mutex> Lock(*getManagedStaticMutex()); - while (StaticList) StaticList->destroy(); } |