diff --git a/libs/libcommon/src/getThreadId.cpp b/libs/libcommon/src/getThreadId.cpp index ee5b63990cb..367c2c43624 100644 --- a/libs/libcommon/src/getThreadId.cpp +++ b/libs/libcommon/src/getThreadId.cpp @@ -1,13 +1,26 @@ -#include -#include #include +#if OS_LINUX + #include + #include +#else + #include + #include +#endif + static thread_local uint64_t current_tid = 0; uint64_t getThreadId() { if (!current_tid) + { +#if OS_LINUX current_tid = syscall(SYS_gettid); /// This call is always successful. - man gettid +#else + if (0 != pthread_threadid_np(nullptr, ¤t_tid) + throw std::logic_error("pthread_threadid_np returned error"); +#endif + } return current_tid; }