Use gettid() syscall under linux to get thread id

This commit is contained in:
gabime 2015-04-07 21:02:34 +03:00
parent a09107927b
commit 4292d3d9af

View File

@ -32,6 +32,9 @@
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# endif # endif
# include <Windows.h> # include <Windows.h>
#elif __linux__
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
#include <unistd.h>
#else #else
#include <pthread.h> #include <pthread.h>
#endif #endif
@ -168,12 +171,14 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime())
#endif #endif
} }
//Return current thread id as 64 bit integer
inline uint64_t thread_id() inline uint64_t thread_id()
{ {
#ifdef _WIN32 #ifdef _WIN32
return ::GetCurrentThreadId(); return ::GetCurrentThreadId();
#elif __linux__
return (uint64_t) syscall(SYS_gettid);
#else #else
return (uint64_t) pthread_self(); return (uint64_t) pthread_self();
#endif #endif