Fix: Use pthread_self to get threadid on OSX
[urcu.git] / tests / common / thread-id.h
CommitLineData
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
CB
20#include <config.h>
21
550265b2 22#ifdef __linux__
9ba261bd 23# include <urcu/syscall-compat.h>
550265b2 24
6bbcdc42
CB
25# if defined(HAVE_GETTID)
26/*
27 * Do not redefine gettid() as it is already included
28 * in bionic through <unistd.h>. Some other libc
29 * may also already contain an implementation of gettid.
30 */
31# elif defined(_syscall0)
550265b2
MD
32_syscall0(pid_t, gettid)
33# elif defined(__NR_gettid)
34static inline pid_t gettid(void)
35{
36 return syscall(__NR_gettid);
37}
38# endif
39
40static inline
41unsigned long urcu_get_thread_id(void)
42{
43 return (unsigned long) gettid();
44}
45#elif defined(__FreeBSD__)
46# include <pthread_np.h>
47
48static inline
49unsigned long urcu_get_thread_id(void)
50{
51 return (unsigned long) pthread_getthreadid_np();
52}
b83b3590 53#elif defined(__sun__) || defined(__APPLE__)
09bdef43
MJ
54#include <pthread.h>
55
56static inline
57unsigned long urcu_get_thread_id(void)
58{
59 return (unsigned long) pthread_self();
60}
550265b2
MD
61#else
62# warning "use pid as thread ID"
63static inline
64unsigned long urcu_get_thread_id(void)
65{
66 return (unsigned long) getpid();
67}
68#endif
69
70#endif /* _TEST_THREAD_ID_H */
This page took 0.030436 seconds and 4 git commands to generate.