1 #ifndef LLDB_THREAD_H 2 #define LLDB_THREAD_H 3 4 #include <stdint.h> 5 6 #if defined(__APPLE__) 7 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2) 8 int pthread_threadid_np(pthread_t, __uint64_t *); 9 #elif defined(__linux__) 10 #include <sys/syscall.h> 11 #include <unistd.h> 12 #elif defined(__NetBSD__) 13 #include <lwp.h> 14 #elif defined(_WIN32) 15 #include <windows.h> 16 #endif 17 18 inline uint64_t get_thread_id() { 19 #if defined(__APPLE__) 20 __uint64_t tid = 0; 21 pthread_threadid_np(pthread_self(), &tid); 22 return tid; 23 #elif defined(__linux__) 24 return syscall(__NR_gettid); 25 #elif defined(__NetBSD__) 26 // Technically lwpid_t is 32-bit signed integer 27 return static_cast<uint64_t>(_lwp_self()); 28 #elif defined(_WIN32) 29 return static_cast<uint64_t>(::GetCurrentThreadId()); 30 #else 31 return -1; 32 #endif 33 } 34 35 #endif // LLDB_THREAD_H 36