[compiler-rt] 9d7b735 - tsan: simplify thread context setting

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 21 04:26:59 PDT 2021


Author: Dmitry Vyukov
Date: 2021-09-21T13:26:55+02:00
New Revision: 9d7b7350c9e00e2a43585328e875bec11c8c8c17

URL: https://github.com/llvm/llvm-project/commit/9d7b7350c9e00e2a43585328e875bec11c8c8c17
DIFF: https://github.com/llvm/llvm-project/commit/9d7b7350c9e00e2a43585328e875bec11c8c8c17.diff

LOG: tsan: simplify thread context setting

Currently we set thr->tctx after OnStarted callback
taking thread registry mutex again and searching for the context.
But OnStarted already runs under the thread registry mutex
and has access to the context, so set it in the OnStarted.
This makes code simpler and faster.

Depends on D110132.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D110133

Added: 
    

Modified: 
    compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
index 9d21f1d092ae..70575754ef70 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
@@ -169,10 +169,6 @@ void ThreadStart(ThreadState *thr, Tid tid, tid_t os_id,
   OnStartedArgs args = { thr, stk_addr, stk_size, tls_addr, tls_size };
   tr->StartThread(tid, os_id, thread_type, &args);
 
-  tr->Lock();
-  thr->tctx = (ThreadContext*)tr->GetThreadLocked(tid);
-  tr->Unlock();
-
   while (!thr->tctx->trace.parts.Empty()) thr->tctx->trace.parts.PopBack();
 
 #if !SANITIZER_GO
@@ -215,6 +211,7 @@ void ThreadContext::OnStarted(void *arg) {
   thr->fast_synch_epoch = epoch0;
   AcquireImpl(thr, 0, &sync);
   sync.Reset(&thr->proc()->clock_cache);
+  thr->tctx = this;
   thr->is_inited = true;
   DPrintf(
       "#%d: ThreadStart epoch=%zu stk_addr=%zx stk_size=%zx "


        


More information about the llvm-commits mailing list