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

llvm-svn: 71853
This commit is contained in:
Owen Anderson 2009-05-15 08:22:07 +00:00
parent 2e38cb19a4
commit 0e4b4929fc
1 changed files with 16 additions and 32 deletions

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);
}