forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththread.h
39 lines (35 loc) · 936 Bytes
/
thread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef LLDB_THREAD_H
#define LLDB_THREAD_H
#include <stdint.h>
#if defined(__APPLE__)
__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
int pthread_threadid_np(pthread_t, __uint64_t *);
#elif defined(__linux__)
#include <sys/syscall.h>
#include <unistd.h>
#elif defined(__FreeBSD__)
#include <pthread_np.h>
#elif defined(__NetBSD__)
#include <lwp.h>
#elif defined(_WIN32)
#include <windows.h>
#endif
inline uint64_t get_thread_id() {
#if defined(__APPLE__)
__uint64_t tid = 0;
pthread_threadid_np(pthread_self(), &tid);
return tid;
#elif defined(__linux__)
return syscall(__NR_gettid);
#elif defined(__FreeBSD__)
return static_cast<uint64_t>(pthread_getthreadid_np());
#elif defined(__NetBSD__)
// Technically lwpid_t is 32-bit signed integer
return static_cast<uint64_t>(_lwp_self());
#elif defined(_WIN32)
return static_cast<uint64_t>(::GetCurrentThreadId());
#else
return -1;
#endif
}
#endif // LLDB_THREAD_H