Commit | Line | Data |
---|---|---|
ce29b371 MJ |
1 | // SPDX-FileCopyrightText: 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
2 | // | |
3 | // SPDX-License-Identifier: LicenseRef-Boehm-GC | |
4 | ||
550265b2 MD |
5 | #ifndef _TEST_THREAD_ID_H |
6 | #define _TEST_THREAD_ID_H | |
7 | ||
8 | /* | |
550265b2 | 9 | * Userspace RCU library - thread ID |
550265b2 | 10 | */ |
6bbcdc42 | 11 | |
550265b2 | 12 | #ifdef __linux__ |
9ba261bd | 13 | # include <urcu/syscall-compat.h> |
550265b2 | 14 | |
6bbcdc42 CB |
15 | # if defined(HAVE_GETTID) |
16 | /* | |
17 | * Do not redefine gettid() as it is already included | |
18 | * in bionic through <unistd.h>. Some other libc | |
19 | * may also already contain an implementation of gettid. | |
20 | */ | |
21 | # elif defined(_syscall0) | |
550265b2 MD |
22 | _syscall0(pid_t, gettid) |
23 | # elif defined(__NR_gettid) | |
24 | static inline pid_t gettid(void) | |
25 | { | |
26 | return syscall(__NR_gettid); | |
27 | } | |
28 | # endif | |
29 | ||
30 | static inline | |
31 | unsigned long urcu_get_thread_id(void) | |
32 | { | |
33 | return (unsigned long) gettid(); | |
34 | } | |
35 | #elif defined(__FreeBSD__) | |
36 | # include <pthread_np.h> | |
37 | ||
38 | static inline | |
39 | unsigned long urcu_get_thread_id(void) | |
40 | { | |
41 | return (unsigned long) pthread_getthreadid_np(); | |
42 | } | |
b83b3590 | 43 | #elif defined(__sun__) || defined(__APPLE__) |
09bdef43 MJ |
44 | #include <pthread.h> |
45 | ||
46 | static inline | |
47 | unsigned long urcu_get_thread_id(void) | |
48 | { | |
49 | return (unsigned long) pthread_self(); | |
50 | } | |
02eb66d8 MJ |
51 | #elif defined(__CYGWIN__) |
52 | #include <pthread.h> | |
53 | ||
54 | extern unsigned long pthread_getsequence_np(pthread_t *); | |
55 | ||
56 | static inline | |
57 | unsigned long urcu_get_thread_id(void) | |
58 | { | |
59 | pthread_t thr = pthread_self(); | |
60 | return pthread_getsequence_np(&thr); | |
61 | } | |
11f3d1c2 BS |
62 | #elif defined(__OpenBSD__) |
63 | #include <unistd.h> | |
02eb66d8 | 64 | |
11f3d1c2 BS |
65 | static inline |
66 | unsigned long urcu_get_thread_id(void) | |
67 | { | |
68 | return (unsigned long) getthrid(); | |
69 | } | |
550265b2 MD |
70 | #else |
71 | # warning "use pid as thread ID" | |
72 | static inline | |
73 | unsigned long urcu_get_thread_id(void) | |
74 | { | |
75 | return (unsigned long) getpid(); | |
76 | } | |
77 | #endif | |
78 | ||
79 | #endif /* _TEST_THREAD_ID_H */ |