[PATCH] Don't use ManagedStatic.

Rui Ueyama ruiu at google.com
Mon Jun 8 00:36:14 PDT 2015


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/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10303.27282.patch
Type: text/x-patch
Size: 734 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150608/3ec1d4a8/attachment.bin>


More information about the llvm-commits mailing list