File: thread-id.h

package info (click to toggle)
liburcu 0.15.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,356 kB
  • sloc: ansic: 23,370; xml: 23,227; sh: 6,480; makefile: 1,045; cpp: 15
file content (79 lines) | stat: -rw-r--r-- 1,593 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-FileCopyrightText: 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
//
// SPDX-License-Identifier: LicenseRef-Boehm-GC

#ifndef _TEST_THREAD_ID_H
#define _TEST_THREAD_ID_H

/*
 * Userspace RCU library - thread ID
 */

#ifdef __linux__
# include <urcu/syscall-compat.h>

# if defined(HAVE_GETTID)
/*
 * Do not redefine gettid() as it is already included
 * in bionic through <unistd.h>. Some other libc
 * may also already contain an implementation of gettid.
 */
# elif defined(_syscall0)
_syscall0(pid_t, gettid)
# elif defined(__NR_gettid)
static inline pid_t gettid(void)
{
	return syscall(__NR_gettid);
}
# endif

static inline
unsigned long urcu_get_thread_id(void)
{
	return (unsigned long) gettid();
}
#elif defined(__FreeBSD__)
# include <pthread_np.h>

static inline
unsigned long urcu_get_thread_id(void)
{
	return (unsigned long) pthread_getthreadid_np();
}
#elif defined(__sun__) || defined(__APPLE__)
#include <pthread.h>

static inline
unsigned long urcu_get_thread_id(void)
{
	return (unsigned long) pthread_self();
}
#elif defined(__CYGWIN__)
#include <pthread.h>

extern unsigned long pthread_getsequence_np(pthread_t *);

static inline
unsigned long urcu_get_thread_id(void)
{
	pthread_t thr = pthread_self();
	return pthread_getsequence_np(&thr);
}
#elif defined(__OpenBSD__)
#include <unistd.h>

static inline
unsigned long urcu_get_thread_id(void)
{
	return (unsigned long) getthrid();
}
#else
# warning "use pid as thread ID"
static inline
unsigned long urcu_get_thread_id(void)
{
	return (unsigned long) getpid();
}
#endif

#endif /* _TEST_THREAD_ID_H */