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)(),
}
/// 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();
}