<div dir="ltr">Looks like C++11 guarantees that the following pattern is thread-safe. So we can do just like this?<div><br></div><div>static Foo &getSingleton() {</div><div>  static Foo x;</div><div>  return x;<br>}</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 8, 2015 at 5:37 AM, Yaron Keren <span dir="ltr"><<a href="mailto:yaron.keren@gmail.com" target="_blank">yaron.keren@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="rtl"><div dir="ltr">Here is the discussion</div><div dir="ltr"><br></div><div dir="ltr"> <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-June/074015.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-June/074015.html</a><br></div><div dir="ltr"><br></div><div dir="ltr">We could go forward with this patch, mingw-w64 support may have improved since then, a year ago, if there are still problems with mingw support of call_once, #ifdef __MINGW32__ the previous solution.</div><div dir="ltr">No reason for all other compilers paying the price.</div><span class="HOEnZb"><font color="#888888"><div dir="ltr"><br></div><div dir="ltr">Yaron</div><div dir="ltr"><br></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote"><div dir="ltr">2015-06-08 15:12 GMT+03:00 Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span>:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We had to revert use of call_once last year because MinGW did not<br>
support it. IIRC, there were a few other issues as well (I have a<br>
vague recollection of an issue with MSVC as well). May want to check<br>
old mailing list posts, as well as the other toolchains, to see how<br>
feasible this is.<br>
<br>
~Aaron<br>
<br>
On Mon, Jun 8, 2015 at 3:36 AM, Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br>
> Hi rafael,<br>
><br>
> ManagedStatic is slow at least on Windows because it calls sys::MemoryFence<br>
> on every access. MSVC profiler reported that LLD is spending 9% on this function.<br>
> This patch is to avoid using that wrapper class and use call_once instead.<br>
><br>
> <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10303&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=a5TfQ4E2fid4yXR1FNMnjT42HCUFGG9tnHcH0QFVMXA&s=3SlzOPf55o1QzeFKYGadbyYupIpeaZDEjMAu91tK_eg&e=" target="_blank">http://reviews.llvm.org/D10303</a><br>
><br>
> Files:<br>
>   lib/Object/Error.cpp<br>
><br>
> Index: lib/Object/Error.cpp<br>
> ===================================================================<br>
> --- lib/Object/Error.cpp<br>
> +++ lib/Object/Error.cpp<br>
> @@ -13,7 +13,7 @@<br>
><br>
>  #include "llvm/Object/Error.h"<br>
>  #include "llvm/Support/ErrorHandling.h"<br>
> -#include "llvm/Support/ManagedStatic.h"<br>
> +#include <mutex><br>
><br>
>  using namespace llvm;<br>
>  using namespace object;<br>
> @@ -55,8 +55,10 @@<br>
>                     "defined.");<br>
>  }<br>
><br>
> -static ManagedStatic<_object_error_category> error_category;<br>
> -<br>
>  const std::error_category &object::object_category() {<br>
> -  return *error_category;<br>
> +  static _object_error_category *Ret;<br>
> +  static std::once_flag Flag;<br>
> +  if (Ret == nullptr)<br>
> +    std::call_once(Flag, []() { Ret = new _object_error_category(); });<br>
> +  return *Ret;<br>
>  }<br>
><br>
> EMAIL PREFERENCES<br>
>   <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_settings_panel_emailpreferences_&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=a5TfQ4E2fid4yXR1FNMnjT42HCUFGG9tnHcH0QFVMXA&s=woyDNhbl4lzNaILS1U7TY-ryqYmvACc4A3wqTyOHru8&e=" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">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>
><br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">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><br></div>
</div></div><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>
<br></blockquote></div><br></div>