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 | */ | |
550265b2 | 20 | #ifdef __linux__ |
9ba261bd | 21 | # include <urcu/syscall-compat.h> |
550265b2 MD |
22 | |
23 | # if defined(_syscall0) | |
24 | _syscall0(pid_t, gettid) | |
25 | # elif defined(__NR_gettid) | |
26 | static inline pid_t gettid(void) | |
27 | { | |
28 | return syscall(__NR_gettid); | |
29 | } | |
30 | # endif | |
31 | ||
32 | static inline | |
33 | unsigned long urcu_get_thread_id(void) | |
34 | { | |
35 | return (unsigned long) gettid(); | |
36 | } | |
37 | #elif defined(__FreeBSD__) | |
38 | # include <pthread_np.h> | |
39 | ||
40 | static inline | |
41 | unsigned long urcu_get_thread_id(void) | |
42 | { | |
43 | return (unsigned long) pthread_getthreadid_np(); | |
44 | } | |
45 | #else | |
46 | # warning "use pid as thread ID" | |
47 | static inline | |
48 | unsigned long urcu_get_thread_id(void) | |
49 | { | |
50 | return (unsigned long) getpid(); | |
51 | } | |
52 | #endif | |
53 | ||
54 | #endif /* _TEST_THREAD_ID_H */ |