Speculative fix for Windows build after r220932
[oota-llvm.git] / lib / Support / Windows / Threading.inc
1 #include <winbase.h>
2
3 #ifdef MemoryFence
4 // WinNT.h seems to define a MemoryFence macro.
5 #undef MemoryFence
6 #endif
7
8 void llvm::call_once(once_flag &flag, void (*fptr)(void)) {
9   while (flag != Done) {
10     if (flag == Wait) {
11       ::Sleep(1);
12       continue;
13     }
14
15     sys::cas_flag old_val = sys::CompareAndSwap(&flag, Wait, Uninitialized);
16     if (old_val == Uninitialized) {
17       fptr();
18       sys::MemoryFence();
19       flag = Done;
20       return;
21     }
22   }
23   sys::MemoryFence();
24 }