diff options
Diffstat (limited to 'llvm/lib/Support/Windows/Threading.inc')
-rw-r--r-- | llvm/lib/Support/Windows/Threading.inc | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc new file mode 100644 index 00000000000..099c6b28bf6 --- /dev/null +++ b/llvm/lib/Support/Windows/Threading.inc @@ -0,0 +1,19 @@ +#include <winbase.h> + +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(); +} |