As pointed out by Duncan, I accidentally dropped the first MemoryFence of the
authorOwen Anderson <resistor@mac.com>
Thu, 18 Jun 2009 16:08:27 +0000 (16:08 +0000)
committerOwen Anderson <resistor@mac.com>
Thu, 18 Jun 2009 16:08:27 +0000 (16:08 +0000)
double-checked locking pattern here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73701 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Pass.cpp

index 579f1029ac378a8963348c84ed2921e12f6fac21..70ec108fa182c3e46b18c0e04842214803912c5d 100644 (file)
@@ -197,17 +197,21 @@ static PassRegistrar *getPassRegistrar() {
   
   // Use double-checked locking to safely initialize the registrar when
   // we're running in multithreaded mode.
-  if (!PassRegistrarObj) {
+  PassRegistrar* tmp = PassRegistrarObj;
+  sys::MemoryFence();
+  if (!tmp) {
     if (llvm_is_multithreaded()) {
       llvm_acquire_global_lock();
-      if (!PassRegistrarObj) {
-        PassRegistrar* tmp = new PassRegistrar();
+      tmp = PassRegistrarObj;
+      if (!tmp) {
+        tmp = new PassRegistrar();
         sys::MemoryFence();
         PassRegistrarObj = tmp;
       }
       llvm_release_global_lock();
-    } else
+    } else {
       PassRegistrarObj = new PassRegistrar();
+    }
   }
   return PassRegistrarObj;
 }