mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-10 02:36:06 +00:00
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:
parent
d300a28c40
commit
ca37b511fa
@ -51,51 +51,35 @@ public:
|
|||||||
///
|
///
|
||||||
template<class C>
|
template<class C>
|
||||||
class ManagedStatic : public ManagedStaticBase {
|
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:
|
public:
|
||||||
|
|
||||||
// Accessors.
|
// Accessors.
|
||||||
C &operator*() {
|
C &operator*() {
|
||||||
sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0);
|
checkInit();
|
||||||
if (OldFlag == 0) {
|
|
||||||
LazyInit();
|
|
||||||
sys::MemoryFence();
|
|
||||||
InitFlag = 2;
|
|
||||||
} else if (OldFlag == 1)
|
|
||||||
while (OldFlag == 1) ;
|
|
||||||
|
|
||||||
return *static_cast<C*>(Ptr);
|
return *static_cast<C*>(Ptr);
|
||||||
}
|
}
|
||||||
C *operator->() {
|
C *operator->() {
|
||||||
sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0);
|
checkInit();
|
||||||
if (OldFlag == 0) {
|
|
||||||
LazyInit();
|
|
||||||
sys::MemoryFence();
|
|
||||||
InitFlag = 2;
|
|
||||||
} else if (OldFlag == 1)
|
|
||||||
while (OldFlag == 1) ;
|
|
||||||
|
|
||||||
return static_cast<C*>(Ptr);
|
return static_cast<C*>(Ptr);
|
||||||
}
|
}
|
||||||
const C &operator*() const {
|
const C &operator*() const {
|
||||||
sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0);
|
checkInit();
|
||||||
if (OldFlag == 0) {
|
|
||||||
LazyInit();
|
|
||||||
sys::MemoryFence();
|
|
||||||
InitFlag = 2;
|
|
||||||
} else if (OldFlag == 1)
|
|
||||||
while (InitFlag == 1) ;
|
|
||||||
|
|
||||||
return *static_cast<C*>(Ptr);
|
return *static_cast<C*>(Ptr);
|
||||||
}
|
}
|
||||||
const C *operator->() const {
|
const C *operator->() const {
|
||||||
sys::cas_flag OldFlag = sys::CompareAndSwap(&InitFlag, 1, 0);
|
checkInit();
|
||||||
if (OldFlag == 0) {
|
|
||||||
LazyInit();
|
|
||||||
sys::MemoryFence();
|
|
||||||
InitFlag = 2;
|
|
||||||
} else if (OldFlag == 1)
|
|
||||||
while (OldFlag == 1) ;
|
|
||||||
|
|
||||||
return static_cast<C*>(Ptr);
|
return static_cast<C*>(Ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user