[PATCH] D19271: Change CALL_ONCE_INITIALIZATION implementation to use static initialization

Mehdi AMINI via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 19 18:12:57 PDT 2016


joker.eph updated this revision to Diff 54307.
joker.eph added a comment.

Improve readability


http://reviews.llvm.org/D19271

Files:
  include/llvm/PassSupport.h

Index: include/llvm/PassSupport.h
===================================================================
--- include/llvm/PassSupport.h
+++ include/llvm/PassSupport.h
@@ -31,25 +31,12 @@
 
 class TargetMachine;
 
-#define CALL_ONCE_INITIALIZATION(function) \
-  static volatile sys::cas_flag initialized = 0; \
-  sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
-  if (old_val == 0) { \
-    function(Registry); \
-    sys::MemoryFence(); \
-    TsanIgnoreWritesBegin(); \
-    TsanHappensBefore(&initialized); \
-    initialized = 2; \
-    TsanIgnoreWritesEnd(); \
-  } else { \
-    sys::cas_flag tmp = initialized; \
-    sys::MemoryFence(); \
-    while (tmp != 2) { \
-      tmp = initialized; \
-      sys::MemoryFence(); \
-    } \
-  } \
-  TsanHappensAfter(&initialized);
+#define CALL_ONCE_INITIALIZATION(function)                                     \
+  static bool initialized_once = [&] {                                         \
+    function(Registry);                                                        \
+    return true;                                                               \
+  }();                                                                         \
+  (void) initialized_once;
 
 #define INITIALIZE_PASS(passName, arg, name, cfg, analysis) \
   static void* initialize##passName##PassOnce(PassRegistry &Registry) { \


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19271.54307.patch
Type: text/x-patch
Size: 1376 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160420/079914bf/attachment.bin>


More information about the llvm-commits mailing list