[PATCH] D123158: make a debug check thread-safe

Luboš Luňák via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 14:13:47 PDT 2022


llunak created this revision.
llunak added a reviewer: urnathan.
llunak added a project: LLVM.
Herald added a project: All.
llunak requested review of this revision.
Herald added a subscriber: llvm-commits.

See https://reviews.llvm.org/D122975#3430613 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123158

Files:
  llvm/include/llvm/Demangle/ItaniumDemangle.h


Index: llvm/include/llvm/Demangle/ItaniumDemangle.h
===================================================================
--- llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -19,6 +19,7 @@
 #include "DemangleConfig.h"
 #include "StringView.h"
 #include "Utility.h"
+#include "llvm/Support/Threading.h"
 #include <algorithm>
 #include <cassert>
 #include <cctype>
@@ -3029,12 +3030,11 @@
 #ifndef NDEBUG
   {
     // Verify table order.
-    static bool Done;
-    if (!Done) {
-      Done = true;
+    static llvm::once_flag Done;
+    llvm::call_once(Done, []() {
       for (const auto *Op = &Ops[0]; Op != &Ops[NumOps - 1]; Op++)
         assert(Op[0] < Op[1] && "Operator table is not ordered");
-    }
+    });
   }
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123158.420631.patch
Type: text/x-patch
Size: 778 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220405/ebdca1d3/attachment.bin>


More information about the llvm-commits mailing list