mirror of
https://github.com/ARMSX2/ARMSX3.git
synced 2026-08-24 16:58:52 -07:00
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()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return GetCurrentThreadId();
|
||||
#elif defined(ANDROID)
|
||||
return static_cast<u64>(pthread_self());
|
||||
#elif defined(__linux__)
|
||||
return syscall(SYS_gettid);
|
||||
#else
|
||||
return reinterpret_cast<u64>(pthread_self());
|
||||
#endif
|
||||
static thread_local u64 s_tls_tid = []() -> u64
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return GetCurrentThreadId();
|
||||
#elif defined(ANDROID)
|
||||
return pthread_gettid_np(pthread_self());
|
||||
#elif defined(__linux__)
|
||||
return syscall(SYS_gettid);
|
||||
#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()
|
||||
|
||||
+10
-2
@@ -186,9 +186,17 @@ namespace
|
||||
#ifdef _WIN32
|
||||
tid = GetCurrentThreadId();
|
||||
#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
|
||||
tid = reinterpret_cast<u64>(pthread_self());
|
||||
tid = pthread_self();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD
|
||||
|
||||
Reference in New Issue
Block a user