Commit | Line | Data |
---|---|---|
550265b2 MD |
1 | #ifndef _TEST_THREAD_ID_H |
2 | #define _TEST_THREAD_ID_H | |
3 | ||
4 | /* | |
5 | * thread-id.h | |
6 | * | |
7 | * Userspace RCU library - thread ID | |
8 | * | |
9 | * Copyright 2013 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | |
10 | * | |
11 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED | |
12 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | |
13 | * | |
14 | * Permission is hereby granted to use or copy this program | |
15 | * for any purpose, provided the above notices are retained on all copies. | |
16 | * Permission to modify the code and to distribute modified code is granted, | |
17 | * provided the above notices are retained, and a notice that the code was | |
18 | * modified is included with the above copyright notice. | |
19 | */ | |
6bbcdc42 | 20 | |
550265b2 | 21 | #ifdef __linux__ |
9ba261bd | 22 | # include <urcu/syscall-compat.h> |
550265b2 | 23 | |
6bbcdc42 CB |
24 | # if defined(HAVE_GETTID) |
25 | /* | |
26 | * Do not redefine gettid() as it is already included | |
27 | * in bionic through <unistd.h>. Some other libc | |
28 | * may also already contain an implementation of gettid. | |
29 | */ | |
30 | # elif defined(_syscall0) | |
550265b2 MD |
31 | _syscall0(pid_t, gettid) |
32 | # elif defined(__NR_gettid) | |
33 | static inline pid_t gettid(void) | |
34 | { | |
35 | return syscall(__NR_gettid); | |
36 | } | |
37 | # endif | |
38 | ||
39 | static inline | |
40 | unsigned long urcu_get_thread_id(void) | |
41 | { | |
42 | return (unsigned long) gettid(); | |
43 | } | |
44 | #elif defined(__FreeBSD__) | |
45 | # include <pthread_np.h> | |
46 | ||
47 | static inline | |
48 | unsigned long urcu_get_thread_id(void) | |
49 | { | |
50 | return (unsigned long) pthread_getthreadid_np(); | |
51 | } | |
b83b3590 | 52 | #elif defined(__sun__) || defined(__APPLE__) |
09bdef43 MJ |
53 | #include <pthread.h> |
54 | ||
55 | static inline | |
56 | unsigned long urcu_get_thread_id(void) | |
57 | { | |
58 | return (unsigned long) pthread_self(); | |
59 | } | |
02eb66d8 MJ |
60 | #elif defined(__CYGWIN__) |
61 | #include <pthread.h> | |
62 | ||
63 | extern unsigned long pthread_getsequence_np(pthread_t *); | |
64 | ||
65 | static inline | |
66 | unsigned long urcu_get_thread_id(void) | |
67 | { | |
68 | pthread_t thr = pthread_self(); | |
69 | return pthread_getsequence_np(&thr); | |
70 | } | |
020351f3 BS |
71 | #elif defined(__OpenBSD__) |
72 | #include <unistd.h> | |
02eb66d8 | 73 | |
020351f3 BS |
74 | static inline |
75 | unsigned long urcu_get_thread_id(void) | |
76 | { | |
77 | return (unsigned long) getthrid(); | |
78 | } | |
550265b2 MD |
79 | #else |
80 | # warning "use pid as thread ID" | |
81 | static inline | |
82 | unsigned long urcu_get_thread_id(void) | |
83 | { | |
84 | return (unsigned long) getpid(); | |
85 | } | |
86 | #endif | |
87 | ||
88 | #endif /* _TEST_THREAD_ID_H */ |