1 // SPDX-FileCopyrightText: 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 // SPDX-License-Identifier: LicenseRef-Boehm-GC
5 #ifndef _TEST_THREAD_ID_H
6 #define _TEST_THREAD_ID_H
9 * Userspace RCU library - thread ID
13 # include <urcu/syscall-compat.h>
15 # if defined(HAVE_GETTID)
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.
21 # elif defined(_syscall0)
22 _syscall0(pid_t
, gettid
)
23 # elif defined(__NR_gettid)
24 static inline pid_t
gettid(void)
26 return syscall(__NR_gettid
);
31 unsigned long urcu_get_thread_id(void)
33 return (unsigned long) gettid();
35 #elif defined(__FreeBSD__)
36 # include <pthread_np.h>
39 unsigned long urcu_get_thread_id(void)
41 return (unsigned long) pthread_getthreadid_np();
43 #elif defined(__sun__) || defined(__APPLE__)
47 unsigned long urcu_get_thread_id(void)
49 return (unsigned long) pthread_self();
51 #elif defined(__CYGWIN__)
54 extern unsigned long pthread_getsequence_np(pthread_t
*);
57 unsigned long urcu_get_thread_id(void)
59 pthread_t thr
= pthread_self();
60 return pthread_getsequence_np(&thr
);
62 #elif defined(__OpenBSD__)
66 unsigned long urcu_get_thread_id(void)
68 return (unsigned long) getthrid();
71 # warning "use pid as thread ID"
73 unsigned long urcu_get_thread_id(void)
75 return (unsigned long) getpid();
79 #endif /* _TEST_THREAD_ID_H */
This page took 0.040875 seconds and 4 git commands to generate.