[llvm-commits] [llvm] r71853 - /llvm/trunk/include/llvm/Support/ManagedStatic.h
Owen Anderson
resistor at mac.com
Fri May 15 01:23:07 PDT 2009
Author: resistor
Date: Fri May 15 03:22:07 2009
New Revision: 71853
URL: http://llvm.org/viewvc/llvm-project?rev=71853&view=rev
Log:
Factor out some common code, fix more typoes, and add a memory fence that might be needed.
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=71853&r1=71852&r2=71853&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ManagedStatic.h (original)
+++ llvm/trunk/include/llvm/Support/ManagedStatic.h Fri May 15 03:22:07 2009
@@ -51,51 +51,35 @@
///
template<class C>
class ManagedStatic : public ManagedStaticBase {
-public:
-
- // Accessors.
- C &operator*() {
+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 (OldFlag == 1) ;
-
+ } else if (OldFlag == 1) {
+ while (InitFlag == 1) ;
+ sys::MemoryFence();
+ }
+ }
+public:
+
+ // Accessors.
+ C &operator*() {
+ checkInit();
return *static_cast<C*>(Ptr);
}
C *operator->() {
- sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0);
- if (OldFlag == 0) {
- LazyInit();
- sys::MemoryFence();
- InitFlag = 2;
- } else if (OldFlag == 1)
- while (OldFlag == 1) ;
-
+ checkInit();
return static_cast<C*>(Ptr);
}
const C &operator*() const {
- sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0);
- if (OldFlag == 0) {
- LazyInit();
- sys::MemoryFence();
- InitFlag = 2;
- } else if (OldFlag == 1)
- while (InitFlag == 1) ;
-
+ checkInit();
return *static_cast<C*>(Ptr);
}
const C *operator->() const {
- sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0);
- if (OldFlag == 0) {
- LazyInit();
- sys::MemoryFence();
- InitFlag = 2;
- } else if (OldFlag == 1)
- while (OldFlag == 1) ;
-
+ checkInit();
return static_cast<C*>(Ptr);
}
More information about the llvm-commits
mailing list