<p dir="ltr">Can you instead use a windows specific api for implementing call once?</p>
<div class="gmail_quote">On Oct 30, 2014 12:09 PM, "Chris Bieneman" <<a href="mailto:beanz@apple.com">beanz@apple.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ugh... So, std::atomic is off the table.<br>
<br>
I think we can do this instead:<br>
<br>
```<br>
void llvm::call_once(once_flag &Initialized, void (*fptr)(void)) {<br>
  while (flag != Done) {<br>
    if (flag == Wait) {<br>
      ::Sleep(1);<br>
      continue;<br>
    }<br>
<br>
    sys::cas_flag old_val = sys::CompareAndSwap(&flag, Wait, Uninitialized);<br>
    if (old_val == Uninitialized) {<br>
      fptr();<br>
      sys::MemoryFence();<br>
      flag = Done;<br>
    }<br>
  }<br>
  sys::MemoryFence();<br>
}<br>
<br>
```<br>
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.<br>
<br>
<a href="http://reviews.llvm.org/D5922" target="_blank">http://reviews.llvm.org/D5922</a><br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>