[compiler-rt] e3b378f - [NFC][lsan] Move SetCurrentThread call

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 16:28:24 PDT 2023


Author: Vitaly Buka
Date: 2023-04-14T16:28:13-07:00
New Revision: e3b378fad95196c721fc2258f325591f21595c81

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

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/lsan/lsan_fuchsia.cpp
    compiler-rt/lib/lsan/lsan_mac.cpp
    compiler-rt/lib/lsan/lsan_posix.cpp
    compiler-rt/lib/lsan/lsan_thread.cpp
    compiler-rt/lib/lsan/lsan_thread.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/lsan/lsan_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_fuchsia.cpp
index 03ac0afbabff7..9bf18cc79b779 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<const OnStartedArgs *>(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 6964a9ba28df5..8302efcdd400b 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 3c7bc15a851af..097dfe05768a7 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<const OnStartedArgs *>(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 137c7e4e4f12c..a0fe95da1a6fa 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 049c7e2038017..66dbc5f35c1cf 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_; }


        


More information about the llvm-commits mailing list