diff --git a/source/common/common/thread.cc b/source/common/common/thread.cc index b8128d2586cf..07e6fa4e84de 100644 --- a/source/common/common/thread.cc +++ b/source/common/common/thread.cc @@ -1,7 +1,13 @@ #include "assert.h" #include "thread.h" +#ifdef linux #include +#elif defined(__FreeBSD__) +#include +#elif defined(__APPLE__) +#include +#endif namespace Thread { @@ -14,7 +20,17 @@ Thread::Thread(std::function thread_routine) : thread_routine_(thread_ro UNREFERENCED_PARAMETER(rc); } -int32_t Thread::currentThreadId() { return syscall(SYS_gettid); } +int32_t Thread::currentThreadId() { +#ifdef linux + return syscall(SYS_gettid); +#elif defined(__APPLE__) + int ret = mach_thread_self(); + mach_port_deallocate(mach_task_self(), ret); + return ret; +#elif defined(__FreeBSD__) + return pthread_getthreadid_np(); +#endif +} void Thread::join() { int rc = pthread_join(thread_id_, nullptr);