44 lines · c
1#ifndef LLDB_THREAD_H2#define LLDB_THREAD_H3 4#include <stdint.h>5 6#if defined(__APPLE__)7__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)8int pthread_threadid_np(pthread_t, __uint64_t *);9#elif defined(__linux__)10#include <sys/syscall.h>11#include <unistd.h>12#elif defined(__FreeBSD__)13#include <pthread_np.h>14#elif defined(__NetBSD__)15#include <lwp.h>16#elif defined(__OpenBSD__)17#include <unistd.h>18#elif defined(_WIN32)19#include <windows.h>20#endif21 22inline uint64_t get_thread_id() {23#if defined(__APPLE__)24 __uint64_t tid = 0;25 pthread_threadid_np(pthread_self(), &tid);26 return tid;27#elif defined(__linux__)28 return syscall(__NR_gettid);29#elif defined(__FreeBSD__)30 return static_cast<uint64_t>(pthread_getthreadid_np());31#elif defined(__NetBSD__)32 // Technically lwpid_t is 32-bit signed integer33 return static_cast<uint64_t>(_lwp_self());34#elif defined(__OpenBSD__)35 return static_cast<uint64_t>(getthrid());36#elif defined(_WIN32)37 return static_cast<uint64_t>(::GetCurrentThreadId());38#else39 return -1;40#endif41}42 43#endif // LLDB_THREAD_H44