[llvm-commits] [llvm] r71931 - /llvm/trunk/include/llvm/Support/ManagedStatic.h

Owen Anderson resistor at mac.com
Sat May 16 00:20:56 PDT 2009


Author: resistor
Date: Sat May 16 02:20:52 2009
New Revision: 71931

URL: http://llvm.org/viewvc/llvm-project?rev=71931&view=rev
Log:
Back out the thread-safe ManagedStatic for now.  Too many people have too many problems with it for the moment.

Modified:
    llvm/trunk/include/llvm/Support/ManagedStatic.h

Modified: llvm/trunk/include/llvm/Support/ManagedStatic.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ManagedStatic.h?rev=71931&r1=71930&r2=71931&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/ManagedStatic.h (original)
+++ llvm/trunk/include/llvm/Support/ManagedStatic.h Sat May 16 02:20:52 2009
@@ -14,8 +14,6 @@
 #ifndef LLVM_SUPPORT_MANAGED_STATIC_H
 #define LLVM_SUPPORT_MANAGED_STATIC_H
 
-#include "llvm/System/Atomic.h"
-
 namespace llvm {
 
 /// object_deleter - Helper method for ManagedStatic.
@@ -28,8 +26,6 @@
 /// ManagedStaticBase - Common base class for ManagedStatic instances.
 class ManagedStaticBase {
 protected:
-  mutable sys::cas_flag InitFlag;
-  
   // This should only be used as a static variable, which guarantees that this
   // will be zero initialized.
   mutable void *Ptr;
@@ -51,35 +47,23 @@
 ///
 template<class C>
 class ManagedStatic : public ManagedStaticBase {
-private:
-  void checkInit() {
-    sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0);
-    if (OldFlag == 0) {
-      LazyInit();
-      sys::MemoryFence();
-      InitFlag = 2;
-    } else if (OldFlag == 1) {
-      while (InitFlag == 1) ;
-      sys::MemoryFence();
-    }
-  }
 public:
 
   // Accessors.
   C &operator*() {
-    checkInit();
+    if (!Ptr) LazyInit();
     return *static_cast<C*>(Ptr);
   }
   C *operator->() {
-    checkInit();
+    if (!Ptr) LazyInit();
     return static_cast<C*>(Ptr);
   }
   const C &operator*() const {
-    checkInit();
+    if (!Ptr) LazyInit();
     return *static_cast<C*>(Ptr);
   }
   const C *operator->() const {
-    checkInit();
+    if (!Ptr) LazyInit();
     return static_cast<C*>(Ptr);
   }
 





More information about the llvm-commits mailing list