uatomic/x86: Remove redundant memory barriers
[urcu.git] / tests / common / thread-id.h
1 // SPDX-FileCopyrightText: 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 //
3 // SPDX-License-Identifier: LicenseRef-Boehm-GC
4
5 #ifndef _TEST_THREAD_ID_H
6 #define _TEST_THREAD_ID_H
7
8 /*
9 * Userspace RCU library - thread ID
10 */
11
12 #ifdef __linux__
13 # include <urcu/syscall-compat.h>
14
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)
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 }
43 #elif defined(__sun__) || defined(__APPLE__)
44 #include <pthread.h>
45
46 static inline
47 unsigned long urcu_get_thread_id(void)
48 {
49 return (unsigned long) pthread_self();
50 }
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 }
62 #elif defined(__OpenBSD__)
63 #include <unistd.h>
64
65 static inline
66 unsigned long urcu_get_thread_id(void)
67 {
68 return (unsigned long) getthrid();
69 }
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 */
This page took 0.031184 seconds and 5 git commands to generate.