Factor out some common code, fix more typoes, and add a memory fence that might be needed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71853 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2009-05-15 08:22:07 +00:00
parent d300a28c40
commit ca37b511fa

View File

@ -51,51 +51,35 @@ public:
///
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*() {
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);
}
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);
}