summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2014-06-16 22:40:42 +0000
committerZachary Turner <zturner@google.com>2014-06-16 22:40:42 +0000
commit89ae856c46a7b83373c433031683936d3f153906 (patch)
tree8039dae504618acf1c5c20f784868e0cfe8dbec1 /llvm/lib
parentd4f7dfe7f2c9e73840e688c6de545ea98ebeb854 (diff)
downloadbcm5719-llvm-89ae856c46a7b83373c433031683936d3f153906.tar.gz
bcm5719-llvm-89ae856c46a7b83373c433031683936d3f153906.zip
Kill the LLVM global lock.
llvm-svn: 211069
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Support/ManagedStatic.cpp23
-rw-r--r--llvm/lib/Support/Threading.cpp5
-rw-r--r--llvm/lib/Support/Timer.cpp2
3 files changed, 23 insertions, 7 deletions
diff --git a/llvm/lib/Support/ManagedStatic.cpp b/llvm/lib/Support/ManagedStatic.cpp
index 1117190888b..ced2b13b3a1 100644
--- a/llvm/lib/Support/ManagedStatic.cpp
+++ b/llvm/lib/Support/ManagedStatic.cpp
@@ -16,16 +16,34 @@
#include "llvm/Support/Atomic.h"
#include "llvm/Support/MutexGuard.h"
#include <cassert>
+#include <mutex>
using namespace llvm;
static const ManagedStaticBase *StaticList = nullptr;
+// ManagedStatics can get created during execution of static constructors. As a
+// result, we cannot use a global static std::mutex object for the lock since it
+// may not have been constructed. Instead, we do a call-once initialization of
+// a pointer to a mutex. This also means that we must not "initialize" the
+// mutex with nullptr, otherwise it might get reset to nullptr after being
+// initialized by std::call_once.
+static std::once_flag MutexInitializationFlag;
+static std::recursive_mutex *ManagedStaticMutex;
+
+namespace {
+ void InitializeManagedStaticMutex() {
+ std::call_once(MutexInitializationFlag,
+ []() { ManagedStaticMutex = new std::recursive_mutex(); });
+ }
+}
+
void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(),
void (*Deleter)(void*)) const {
assert(Creator);
if (llvm_is_multithreaded()) {
- llvm::MutexGuard Lock(llvm::llvm_get_global_lock());
+ InitializeManagedStaticMutex();
+ std::lock_guard<std::recursive_mutex> Lock(*ManagedStaticMutex);
if (!Ptr) {
void* tmp = Creator();
@@ -74,6 +92,9 @@ void ManagedStaticBase::destroy() const {
/// llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
void llvm::llvm_shutdown() {
+ InitializeManagedStaticMutex();
+ std::lock_guard<std::recursive_mutex> Lock(*ManagedStaticMutex);
+
while (StaticList)
StaticList->destroy();
}
diff --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp
index ff591aaa1d8..838a71b789d 100644
--- a/llvm/lib/Support/Threading.cpp
+++ b/llvm/lib/Support/Threading.cpp
@@ -20,11 +20,6 @@
using namespace llvm;
-sys::Mutex& llvm::llvm_get_global_lock() {
- static sys::Mutex global_lock;
- return global_lock;
-}
-
bool llvm::llvm_is_multithreaded() {
#if LLVM_ENABLE_THREADS != 0
return true;
diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp
index c7427260bff..7738283bad0 100644
--- a/llvm/lib/Support/Timer.cpp
+++ b/llvm/lib/Support/Timer.cpp
@@ -84,7 +84,7 @@ static TimerGroup *getDefaultTimerGroup() {
sys::MemoryFence();
if (tmp) return tmp;
- llvm::MutexGuard Lock(llvm::llvm_get_global_lock());
+ sys::SmartScopedLock<true> Lock(*TimerLock);
tmp = DefaultTimerGroup;
if (!tmp) {
tmp = new TimerGroup("Miscellaneous Ungrouped Timers");
OpenPOWER on IntegriCloud