[PATCH] Don't use ManagedStatic.
Aaron Ballman
aaron at aaronballman.com
Mon Jun 8 05:12:06 PDT 2015
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
>
> 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
>
More information about the llvm-commits
mailing list