Use kernel thread ids on linux.

This commit is contained in:
Bartosz Taudul 2019-08-14 01:57:10 +02:00
parent 8925d026a9
commit 339b7fd2a6

View File

@ -15,6 +15,13 @@ extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(void
# include <pthread.h> # include <pthread.h>
#endif #endif
#ifdef __ANDROID__
# include <sys/types.h>
#elif defined __linux__
# include <unistd.h>
# include <sys/syscall.h>
#endif
#include <stdint.h> #include <stdint.h>
#include <thread> #include <thread>
@ -34,6 +41,10 @@ static inline uint64_t GetThreadHandleImpl()
uint64_t id; uint64_t id;
pthread_threadid_np( pthread_self(), &id ); pthread_threadid_np( pthread_self(), &id );
return id; return id;
#elif defined __ANDROID__
return (uint64_t)gettid();
#elif defined __linux__
return (uint64_t)syscall( SYS_gettid );
#else #else
static_assert( sizeof( decltype( pthread_self() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" ); static_assert( sizeof( decltype( pthread_self() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" );
return uint64_t( pthread_self() ); return uint64_t( pthread_self() );