[PATCH] Removing the static initializer in ManagedStatic.cpp by using llvm_call_once to initialize the ManagedStatic mutex.
Chandler Carruth
chandlerc at gmail.com
Thu Oct 30 12:41:57 PDT 2014
Can you instead use a windows specific api for implementing call once?
On Oct 30, 2014 12:09 PM, "Chris Bieneman" <beanz at apple.com> wrote:
> 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
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141030/c21d1e4f/attachment.html>
More information about the llvm-commits
mailing list