Avoid using pthread_self() partially
This commit is contained in:
+20
-9
@@ -3560,15 +3560,26 @@ std::pair<void*, usz> thread_ctrl::get_thread_stack()
|
|||||||
|
|
||||||
u64 thread_ctrl::get_tid()
|
u64 thread_ctrl::get_tid()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
static thread_local u64 s_tls_tid = []() -> u64
|
||||||
return GetCurrentThreadId();
|
{
|
||||||
#elif defined(ANDROID)
|
#ifdef _WIN32
|
||||||
return static_cast<u64>(pthread_self());
|
return GetCurrentThreadId();
|
||||||
#elif defined(__linux__)
|
#elif defined(ANDROID)
|
||||||
return syscall(SYS_gettid);
|
return pthread_gettid_np(pthread_self());
|
||||||
#else
|
#elif defined(__linux__)
|
||||||
return reinterpret_cast<u64>(pthread_self());
|
return syscall(SYS_gettid);
|
||||||
#endif
|
#elif defined(__APPLE__)
|
||||||
|
u64 tid{};
|
||||||
|
pthread_threadid_np(nullptr, &tid);
|
||||||
|
return tid;
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
return pthread_getthreadid_np();
|
||||||
|
#else
|
||||||
|
return static_cast<u64>(pthread_self());
|
||||||
|
#endif
|
||||||
|
}();
|
||||||
|
|
||||||
|
return s_tls_tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool thread_ctrl::is_main()
|
bool thread_ctrl::is_main()
|
||||||
|
|||||||
+10
-2
@@ -186,9 +186,17 @@ namespace
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
tid = GetCurrentThreadId();
|
tid = GetCurrentThreadId();
|
||||||
#elif defined(ANDROID)
|
#elif defined(ANDROID)
|
||||||
tid = pthread_self();
|
tid = pthread_gettid_np(pthread_self());
|
||||||
|
#elif defined(__linux__)
|
||||||
|
tid = syscall(SYS_gettid);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
u64 tid_temp{};
|
||||||
|
pthread_threadid_np(nullptr, &tid_temp);
|
||||||
|
tid = tid_temp; // Use a temporary for extra safety
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
tid = pthread_getthreadid_np();
|
||||||
#else
|
#else
|
||||||
tid = reinterpret_cast<u64>(pthread_self());
|
tid = pthread_self();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_STD
|
#ifdef USE_STD
|
||||||
|
|||||||
Reference in New Issue
Block a user