summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Windows/Threading.inc
blob: 196be890dbfddbafd1b2eeca76f796e27634bb0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 #include <windows.h>

#ifdef MemoryFence
// WinNT.h seems to define a MemoryFence macro.
#undef MemoryFence
#endif

void llvm::call_once(once_flag &flag, 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;
      return;
    }
  }
  sys::MemoryFence();
}
OpenPOWER on IntegriCloud