[PATCH] Don't use ManagedStatic.

Rui Ueyama ruiu at google.com
Mon Jun 8 09:05:49 PDT 2015


Looks like C++11 guarantees that the following pattern is thread-safe. So
we can do just like this?

static Foo &getSingleton() {
  static Foo x;
  return x;
}


On Mon, Jun 8, 2015 at 5:37 AM, Yaron Keren <yaron.keren at gmail.com> wrote:

> Here is the discussion
>
>  http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-June/074015.html
>
> 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.
> No reason for all other compilers paying the price.
>
> Yaron
>
>
> 2015-06-08 15:12 GMT+03:00 Aaron Ballman <aaron at aaronballman.com>:
>
>> We had to revert use of call_once last year because MinGW did not
>> support it. IIRC, there were a few other issues as well (I have a
>> vague recollection of an issue with MSVC as well). May want to check
>> old mailing list posts, as well as the other toolchains, to see how
>> feasible this is.
>>
>> ~Aaron
>>
>> On Mon, Jun 8, 2015 at 3:36 AM, Rui Ueyama <ruiu at google.com> wrote:
>> > Hi rafael,
>> >
>> > ManagedStatic is slow at least on Windows because it calls
>> sys::MemoryFence
>> > on every access. MSVC profiler reported that LLD is spending 9% on this
>> function.
>> > This patch is to avoid using that wrapper class and use call_once
>> instead.
>> >
>> > http://reviews.llvm.org/D10303
>> <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=>
>> >
>> > Files:
>> >   lib/Object/Error.cpp
>> >
>> > Index: lib/Object/Error.cpp
>> > ===================================================================
>> > --- lib/Object/Error.cpp
>> > +++ lib/Object/Error.cpp
>> > @@ -13,7 +13,7 @@
>> >
>> >  #include "llvm/Object/Error.h"
>> >  #include "llvm/Support/ErrorHandling.h"
>> > -#include "llvm/Support/ManagedStatic.h"
>> > +#include <mutex>
>> >
>> >  using namespace llvm;
>> >  using namespace object;
>> > @@ -55,8 +55,10 @@
>> >                     "defined.");
>> >  }
>> >
>> > -static ManagedStatic<_object_error_category> error_category;
>> > -
>> >  const std::error_category &object::object_category() {
>> > -  return *error_category;
>> > +  static _object_error_category *Ret;
>> > +  static std::once_flag Flag;
>> > +  if (Ret == nullptr)
>> > +    std::call_once(Flag, []() { Ret = new _object_error_category(); });
>> > +  return *Ret;
>> >  }
>> >
>> > EMAIL PREFERENCES
>> >   http://reviews.llvm.org/settings/panel/emailpreferences/
>> <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=>
>> >
>> > _______________________________________________
>> > llvm-commits mailing list
>> > llvm-commits at cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>> >
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
> _______________________________________________
> 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/20150608/91ed576c/attachment.html>


More information about the llvm-commits mailing list