<div dir="ltr">This change was reverted in r211072 due to accidentally pushing a whole branch instead of a single CL.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 16, 2014 at 3:40 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: zturner<br>
Date: Mon Jun 16 17:40:42 2014<br>
New Revision: 211069<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=211069&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=211069&view=rev</a><br>
Log:<br>
Kill the LLVM global lock.<br>
<br>
Modified:<br>
llvm/trunk/include/llvm/Support/Threading.h<br>
llvm/trunk/lib/Support/ManagedStatic.cpp<br>
llvm/trunk/lib/Support/Threading.cpp<br>
llvm/trunk/lib/Support/Timer.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Support/Threading.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Threading.h?rev=211069&r1=211068&r2=211069&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Threading.h?rev=211069&r1=211068&r2=211069&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/Threading.h (original)<br>
+++ llvm/trunk/include/llvm/Support/Threading.h Mon Jun 16 17:40:42 2014<br>
@@ -18,9 +18,6 @@<br>
#include "llvm/Support/Mutex.h"<br>
<br>
namespace llvm {<br>
- /// llvm_get_global_lock - returns the llvm global lock object.<br>
- sys::Mutex &llvm_get_global_lock();<br>
-<br>
/// llvm_is_multithreaded - returns true if LLVM is compiled with support<br>
/// for multiple threads, and false otherwise.<br>
bool llvm_is_multithreaded();<br>
<br>
Modified: llvm/trunk/lib/Support/ManagedStatic.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ManagedStatic.cpp?rev=211069&r1=211068&r2=211069&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ManagedStatic.cpp?rev=211069&r1=211068&r2=211069&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/ManagedStatic.cpp (original)<br>
+++ llvm/trunk/lib/Support/ManagedStatic.cpp Mon Jun 16 17:40:42 2014<br>
@@ -16,16 +16,34 @@<br>
#include "llvm/Support/Atomic.h"<br>
#include "llvm/Support/MutexGuard.h"<br>
#include <cassert><br>
+#include <mutex><br>
using namespace llvm;<br>
<br>
static const ManagedStaticBase *StaticList = nullptr;<br>
<br>
+// ManagedStatics can get created during execution of static constructors. As a<br>
+// result, we cannot use a global static std::mutex object for the lock since it<br>
+// may not have been constructed. Instead, we do a call-once initialization of<br>
+// a pointer to a mutex. This also means that we must not "initialize" the<br>
+// mutex with nullptr, otherwise it might get reset to nullptr after being<br>
+// initialized by std::call_once.<br>
+static std::once_flag MutexInitializationFlag;<br>
+static std::recursive_mutex *ManagedStaticMutex;<br>
+<br>
+namespace {<br>
+ void InitializeManagedStaticMutex() {<br>
+ std::call_once(MutexInitializationFlag,<br>
+ []() { ManagedStaticMutex = new std::recursive_mutex(); });<br>
+ }<br>
+}<br>
+<br>
void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(),<br>
void (*Deleter)(void*)) const {<br>
assert(Creator);<br>
if (llvm_is_multithreaded()) {<br>
- llvm::MutexGuard Lock(llvm::llvm_get_global_lock());<br>
+ InitializeManagedStaticMutex();<br>
<br>
+ std::lock_guard<std::recursive_mutex> Lock(*ManagedStaticMutex);<br>
if (!Ptr) {<br>
void* tmp = Creator();<br>
<br>
@@ -74,6 +92,9 @@ void ManagedStaticBase::destroy() const<br>
<br>
/// llvm_shutdown - Deallocate and destroy all ManagedStatic variables.<br>
void llvm::llvm_shutdown() {<br>
+ InitializeManagedStaticMutex();<br>
+ std::lock_guard<std::recursive_mutex> Lock(*ManagedStaticMutex);<br>
+<br>
while (StaticList)<br>
StaticList->destroy();<br>
}<br>
<br>
Modified: llvm/trunk/lib/Support/Threading.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Threading.cpp?rev=211069&r1=211068&r2=211069&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Threading.cpp?rev=211069&r1=211068&r2=211069&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Threading.cpp (original)<br>
+++ llvm/trunk/lib/Support/Threading.cpp Mon Jun 16 17:40:42 2014<br>
@@ -20,11 +20,6 @@<br>
<br>
using namespace llvm;<br>
<br>
-sys::Mutex& llvm::llvm_get_global_lock() {<br>
- static sys::Mutex global_lock;<br>
- return global_lock;<br>
-}<br>
-<br>
bool llvm::llvm_is_multithreaded() {<br>
#if LLVM_ENABLE_THREADS != 0<br>
return true;<br>
<br>
Modified: llvm/trunk/lib/Support/Timer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Timer.cpp?rev=211069&r1=211068&r2=211069&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Timer.cpp?rev=211069&r1=211068&r2=211069&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Timer.cpp (original)<br>
+++ llvm/trunk/lib/Support/Timer.cpp Mon Jun 16 17:40:42 2014<br>
@@ -84,7 +84,7 @@ static TimerGroup *getDefaultTimerGroup(<br>
sys::MemoryFence();<br>
if (tmp) return tmp;<br>
<br>
- llvm::MutexGuard Lock(llvm::llvm_get_global_lock());<br>
+ sys::SmartScopedLock<true> Lock(*TimerLock);<br>
tmp = DefaultTimerGroup;<br>
if (!tmp) {<br>
tmp = new TimerGroup("Miscellaneous Ungrouped Timers");<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>