[PATCH] Removing the static initializer in ManagedStatic.cpp by using llvm_call_once to initialize the ManagedStatic mutex.
Chris Bieneman
beanz at apple.com
Thu Oct 30 12:06:03 PDT 2014
Ugh... So, std::atomic is off the table.
I think we can do this instead:
```
void llvm::call_once(once_flag &Initialized, void (*fptr)(void)) {
while (flag != Done) {
if (flag == Wait) {
::Sleep(1);
continue;
}
sys::cas_flag old_val = sys::CompareAndSwap(&flag, Wait, Uninitialized);
if (old_val == Uninitialized) {
fptr();
sys::MemoryFence();
flag = Done;
}
}
sys::MemoryFence();
}
```
It ends up being a bit conservative on MemFences on x86, but it should be safe, and since once_flag is just an unsigned, it has a trivial static initializer and should avoid the issue that std::atomic has.
http://reviews.llvm.org/D5922
More information about the llvm-commits
mailing list