[compiler-rt] 4887995 - [NFC][ASAN] Extract ThreadRegistry initialization

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Mon May 8 00:24:57 PDT 2023


Author: Vitaly Buka
Date: 2023-05-08T00:24:37-07:00
New Revision: 488799599f6f902c051e50b72e21472e202c4004

URL: https://github.com/llvm/llvm-project/commit/488799599f6f902c051e50b72e21472e202c4004
DIFF: https://github.com/llvm/llvm-project/commit/488799599f6f902c051e50b72e21472e202c4004.diff

LOG: [NFC][ASAN] Extract ThreadRegistry initialization

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_thread.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_thread.cpp b/compiler-rt/lib/asan/asan_thread.cpp
index af228f5a3a53..ebe96a841a5c 100644
--- a/compiler-rt/lib/asan/asan_thread.cpp
+++ b/compiler-rt/lib/asan/asan_thread.cpp
@@ -52,19 +52,23 @@ static ThreadContextBase *GetAsanThreadContext(u32 tid) {
   return new (allocator_for_thread_context) AsanThreadContext(tid);
 }
 
-ThreadRegistry &asanThreadRegistry() {
+static void InitThreads() {
   static bool initialized;
   // Don't worry about thread_safety - this should be called when there is
   // a single thread.
-  if (!initialized) {
-    // Never reuse ASan threads: we store pointer to AsanThreadContext
-    // in TSD and can't reliably tell when no more TSD destructors will
-    // be called. It would be wrong to reuse AsanThreadContext for another
-    // thread before all TSD destructors will be called for it.
-    asan_thread_registry =
-        new (thread_registry_placeholder) ThreadRegistry(GetAsanThreadContext);
-    initialized = true;
-  }
+  if (LIKELY(initialized))
+    return;
+  // Never reuse ASan threads: we store pointer to AsanThreadContext
+  // in TSD and can't reliably tell when no more TSD destructors will
+  // be called. It would be wrong to reuse AsanThreadContext for another
+  // thread before all TSD destructors will be called for it.
+  asan_thread_registry =
+      new (thread_registry_placeholder) ThreadRegistry(GetAsanThreadContext);
+  initialized = true;
+}
+
+ThreadRegistry &asanThreadRegistry() {
+  InitThreads();
   return *asan_thread_registry;
 }
 


        


More information about the llvm-commits mailing list