[PATCH] Don't use ManagedStatic.

Benjamin Kramer benny.kra at gmail.com
Mon Jun 8 05:32:01 PDT 2015


> On 08.06.2015, at 14:12, Aaron Ballman <aaron at aaronballman.com> wrote:
> 
> 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.

Can we rely on thread safe statics instead? It's the natural pattern for this kind of code and will eventually have zero overhead as soon as we switch to a C++14 standard library where std::error_category has a constexpr ctor.

- Ben

> 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
>> 
>> 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/
>> 
>> _______________________________________________
>> 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





More information about the llvm-commits mailing list