From: Vitaly Buka Date: Fri, 14 Apr 2023 22:43:56 +0000 (-0700) Subject: [NFC][lsan] Move SetCurrentThread call X-Git-Tag: upstream/17.0.6~11529 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e3b378fad95196c721fc2258f325591f21595c81;p=platform%2Fupstream%2Fllvm.git [NFC][lsan] Move SetCurrentThread call Future patch will set the current context as well. Existing callsite requires additional lock to find context. Differential Revision: https://reviews.llvm.org/D148390 --- diff --git a/compiler-rt/lib/lsan/lsan_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_fuchsia.cpp index 03ac0af..9bf18cc 100644 --- a/compiler-rt/lib/lsan/lsan_fuchsia.cpp +++ b/compiler-rt/lib/lsan/lsan_fuchsia.cpp @@ -46,6 +46,7 @@ struct OnStartedArgs { }; void ThreadContext::OnStarted(void *arg) { + ThreadContextLsanBase::OnStarted(arg); auto args = reinterpret_cast(arg); cache_begin_ = args->cache_begin; cache_end_ = args->cache_end; diff --git a/compiler-rt/lib/lsan/lsan_mac.cpp b/compiler-rt/lib/lsan/lsan_mac.cpp index 6964a9b..8302efc 100644 --- a/compiler-rt/lib/lsan/lsan_mac.cpp +++ b/compiler-rt/lib/lsan/lsan_mac.cpp @@ -70,7 +70,6 @@ void lsan_register_worker_thread(int parent_tid) { if (GetCurrentThread() == kInvalidTid) { u32 tid = ThreadCreate(parent_tid, true); ThreadStart(tid, GetTid()); - SetCurrentThread(tid); } } diff --git a/compiler-rt/lib/lsan/lsan_posix.cpp b/compiler-rt/lib/lsan/lsan_posix.cpp index 3c7bc15..097dfe0 100644 --- a/compiler-rt/lib/lsan/lsan_posix.cpp +++ b/compiler-rt/lib/lsan/lsan_posix.cpp @@ -35,6 +35,7 @@ struct OnStartedArgs { }; void ThreadContext::OnStarted(void *arg) { + ThreadContextLsanBase::OnStarted(arg); auto args = reinterpret_cast(arg); stack_begin_ = args->stack_begin; stack_end_ = args->stack_end; diff --git a/compiler-rt/lib/lsan/lsan_thread.cpp b/compiler-rt/lib/lsan/lsan_thread.cpp index 137c7e4..a0fe95d 100644 --- a/compiler-rt/lib/lsan/lsan_thread.cpp +++ b/compiler-rt/lib/lsan/lsan_thread.cpp @@ -39,9 +39,12 @@ void InitializeThreadRegistry() { ThreadContextLsanBase::ThreadContextLsanBase(int tid) : ThreadContextBase(tid) {} +void ThreadContextLsanBase::OnStarted(void *arg) { SetCurrentThread(tid); } + void ThreadContextLsanBase::OnFinished() { AllocatorThreadFinish(); DTLS_Destroy(); + SetCurrentThread(kInvalidTid); } u32 ThreadCreate(u32 parent_tid, bool detached, void *arg) { @@ -51,13 +54,9 @@ u32 ThreadCreate(u32 parent_tid, bool detached, void *arg) { void ThreadContextLsanBase::ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type, void *arg) { thread_registry->StartThread(tid, os_id, thread_type, arg); - SetCurrentThread(tid); } -void ThreadFinish() { - thread_registry->FinishThread(GetCurrentThread()); - SetCurrentThread(kInvalidTid); -} +void ThreadFinish() { thread_registry->FinishThread(GetCurrentThread()); } ThreadContext *CurrentThreadContext() { if (!thread_registry) diff --git a/compiler-rt/lib/lsan/lsan_thread.h b/compiler-rt/lib/lsan/lsan_thread.h index 049c7e2..66dbc5f 100644 --- a/compiler-rt/lib/lsan/lsan_thread.h +++ b/compiler-rt/lib/lsan/lsan_thread.h @@ -21,6 +21,7 @@ namespace __lsan { class ThreadContextLsanBase : public ThreadContextBase { public: explicit ThreadContextLsanBase(int tid); + void OnStarted(void *arg) override; void OnFinished() override; uptr stack_begin() { return stack_begin_; } uptr stack_end() { return stack_end_; }