[compiler-rt] 02eb818 - [NFC][lsan] Add GetCurrentThreadId wrapper for GetCurrentThread
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 14 23:03:02 PDT 2023
Author: Vitaly Buka
Date: 2023-04-14T23:02:15-07:00
New Revision: 02eb818f64c3b5e20f1badfe803a9a22f9de4640
URL: https://github.com/llvm/llvm-project/commit/02eb818f64c3b5e20f1badfe803a9a22f9de4640
DIFF: https://github.com/llvm/llvm-project/commit/02eb818f64c3b5e20f1badfe803a9a22f9de4640.diff
LOG: [NFC][lsan] Add GetCurrentThreadId wrapper for GetCurrentThread
I am going to change return type of GetCurrentThreadId() in the next
patch.
Differential Revision: https://reviews.llvm.org/D148394
Added:
Modified:
compiler-rt/lib/lsan/lsan_fuchsia.cpp
compiler-rt/lib/lsan/lsan_interceptors.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 9bf18cc79b779..4edac9757a9c4 100644
--- a/compiler-rt/lib/lsan/lsan_fuchsia.cpp
+++ b/compiler-rt/lib/lsan/lsan_fuchsia.cpp
@@ -99,7 +99,7 @@ void *__sanitizer_before_thread_create_hook(thrd_t thread, bool detached,
OnCreatedArgs args;
args.stack_begin = reinterpret_cast<uptr>(stack_base);
args.stack_end = args.stack_begin + stack_size;
- u32 parent_tid = GetCurrentThread();
+ u32 parent_tid = GetCurrentThreadId();
u32 tid = ThreadCreate(parent_tid, detached, &args);
return reinterpret_cast<void *>(static_cast<uptr>(tid));
}
diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp
index 3a1b2afdbb74e..3f8ef3fe48c2d 100644
--- a/compiler-rt/lib/lsan/lsan_interceptors.cpp
+++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp
@@ -468,7 +468,7 @@ INTERCEPTOR(int, pthread_create, void *th, void *attr,
res = REAL(pthread_create)(th, attr, __lsan_thread_start_func, &p);
}
if (res == 0) {
- int tid = ThreadCreate(GetCurrentThread(), IsStateDetached(detached));
+ int tid = ThreadCreate(GetCurrentThreadId(), IsStateDetached(detached));
CHECK_NE(tid, kMainTid);
atomic_store(&p.tid, tid, memory_order_release);
while (atomic_load(&p.tid, memory_order_acquire) != 0)
diff --git a/compiler-rt/lib/lsan/lsan_mac.cpp b/compiler-rt/lib/lsan/lsan_mac.cpp
index 8302efcdd400b..2bcd0057f24b0 100644
--- a/compiler-rt/lib/lsan/lsan_mac.cpp
+++ b/compiler-rt/lib/lsan/lsan_mac.cpp
@@ -67,7 +67,7 @@ typedef struct {
ALWAYS_INLINE
void lsan_register_worker_thread(int parent_tid) {
- if (GetCurrentThread() == kInvalidTid) {
+ if (GetCurrentThreadId() == kInvalidTid) {
u32 tid = ThreadCreate(parent_tid, true);
ThreadStart(tid, GetTid());
}
@@ -100,7 +100,7 @@ extern "C" lsan_block_context_t *alloc_lsan_context(void *ctxt,
(lsan_block_context_t *)lsan_malloc(sizeof(lsan_block_context_t), stack);
lsan_ctxt->block = ctxt;
lsan_ctxt->func = func;
- lsan_ctxt->parent_tid = GetCurrentThread();
+ lsan_ctxt->parent_tid = GetCurrentThreadId();
return lsan_ctxt;
}
@@ -145,13 +145,13 @@ void dispatch_source_set_event_handler(dispatch_source_t ds,
void (^work)(void));
}
-#define GET_LSAN_BLOCK(work) \
- void (^lsan_block)(void); \
- int parent_tid = GetCurrentThread(); \
- lsan_block = ^(void) { \
- lsan_register_worker_thread(parent_tid); \
- work(); \
- }
+# define GET_LSAN_BLOCK(work) \
+ void (^lsan_block)(void); \
+ int parent_tid = GetCurrentThreadId(); \
+ lsan_block = ^(void) { \
+ lsan_register_worker_thread(parent_tid); \
+ work(); \
+ }
INTERCEPTOR(void, dispatch_async, dispatch_queue_t dq, void (^work)(void)) {
GET_LSAN_BLOCK(work);
diff --git a/compiler-rt/lib/lsan/lsan_posix.cpp b/compiler-rt/lib/lsan/lsan_posix.cpp
index 097dfe05768a7..d99e1cc0105ef 100644
--- a/compiler-rt/lib/lsan/lsan_posix.cpp
+++ b/compiler-rt/lib/lsan/lsan_posix.cpp
@@ -89,7 +89,7 @@ static void OnStackUnwind(const SignalContext &sig, const void *,
}
void LsanOnDeadlySignal(int signo, void *siginfo, void *context) {
- HandleDeadlySignal(siginfo, context, GetCurrentThread(), &OnStackUnwind,
+ HandleDeadlySignal(siginfo, context, GetCurrentThreadId(), &OnStackUnwind,
nullptr);
}
diff --git a/compiler-rt/lib/lsan/lsan_thread.cpp b/compiler-rt/lib/lsan/lsan_thread.cpp
index a0fe95da1a6fa..bc05021e98a99 100644
--- a/compiler-rt/lib/lsan/lsan_thread.cpp
+++ b/compiler-rt/lib/lsan/lsan_thread.cpp
@@ -56,19 +56,20 @@ void ThreadContextLsanBase::ThreadStart(u32 tid, tid_t os_id,
thread_registry->StartThread(tid, os_id, thread_type, arg);
}
-void ThreadFinish() { thread_registry->FinishThread(GetCurrentThread()); }
+void ThreadFinish() { thread_registry->FinishThread(GetCurrentThreadId()); }
ThreadContext *CurrentThreadContext() {
if (!thread_registry)
return nullptr;
- if (GetCurrentThread() == kInvalidTid)
+ if (GetCurrentThreadId() == kInvalidTid)
return nullptr;
// No lock needed when getting current thread.
- return (ThreadContext *)thread_registry->GetThreadLocked(GetCurrentThread());
+ return (ThreadContext *)thread_registry->GetThreadLocked(
+ GetCurrentThreadId());
}
void EnsureMainThreadIDIsCorrect() {
- if (GetCurrentThread() == kMainTid)
+ if (GetCurrentThreadId() == kMainTid)
CurrentThreadContext()->os_id = GetTid();
}
diff --git a/compiler-rt/lib/lsan/lsan_thread.h b/compiler-rt/lib/lsan/lsan_thread.h
index 66dbc5f35c1cf..5abbaff539764 100644
--- a/compiler-rt/lib/lsan/lsan_thread.h
+++ b/compiler-rt/lib/lsan/lsan_thread.h
@@ -52,6 +52,7 @@ u32 ThreadCreate(u32 tid, bool detached, void *arg = nullptr);
void ThreadFinish();
u32 GetCurrentThread();
+inline u32 GetCurrentThreadId() { return GetCurrentThread(); }
void SetCurrentThread(u32 tid);
ThreadContext *CurrentThreadContext();
void EnsureMainThreadIDIsCorrect();
More information about the llvm-commits
mailing list