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
This commit is contained in:
Dmitry Vyukov 2021-09-21 10:20:24 +02:00
parent 908256b0ea
commit 9d7b7350c9
1 changed files with 1 additions and 4 deletions

View File

@ -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 "