1 #ifndef _LTTNG_UST_FUTEX_H
2 #define _LTTNG_UST_FUTEX_H
7 * Userspace RCU - sys_futex/compat_futex header.
9 * Copyright 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <sys/syscall.h>
39 * sys_futex compatibility header.
40 * Use *only* *either of* futex_noasync OR futex_async on a given address.
42 * futex_noasync cannot be executed in signal handlers, but ensures that
43 * it will be put in a wait queue even in compatibility mode.
45 * futex_async is signal-handler safe for the wakeup. It uses polling
46 * on the wait-side in compatibility mode.
48 * BEWARE: sys_futex() FUTEX_WAIT may return early if interrupted
52 extern int lttng_ust_compat_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
53 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
);
54 extern int lttng_ust_compat_futex_async(int32_t *uaddr
, int op
, int32_t val
,
55 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
);
57 #if (defined(__linux__) && defined(__NR_futex))
61 #include <urcu/compiler.h>
62 #include <urcu/arch.h>
64 static inline int lttng_ust_futex(int32_t *uaddr
, int op
, int32_t val
,
65 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
67 return syscall(__NR_futex
, uaddr
, op
, val
, timeout
,
71 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
72 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
76 ret
= lttng_ust_futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
77 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
79 * The fallback on ENOSYS is the async-safe version of
80 * the compat futex implementation, because the
81 * async-safe compat implementation allows being used
82 * concurrently with calls to futex(). Indeed, sys_futex
83 * FUTEX_WAIT, on some architectures (mips and parisc),
84 * within a given process, spuriously return ENOSYS due
85 * to signal restart bugs on some kernel versions.
87 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
,
94 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
95 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
99 ret
= lttng_ust_futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
100 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
101 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
,
107 #elif defined(__FreeBSD__)
109 #include <sys/types.h>
110 #include <sys/umtx.h>
112 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
113 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
116 void *umtx_uaddr
= NULL
, *umtx_uaddr2
= NULL
;
117 struct _umtx_time umtx_timeout
= {
118 ._flags
= UMTX_ABSTIME
,
119 ._clockid
= CLOCK_MONOTONIC
,
124 /* On FreeBSD, a "u_int" is a 32-bit integer. */
125 umtx_op
= UMTX_OP_WAIT_UINT
;
126 if (timeout
!= NULL
) {
127 umtx_timeout
._timeout
= *timeout
;
128 umtx_uaddr
= (void *) sizeof(umtx_timeout
);
129 umtx_uaddr2
= (void *) &umtx_timeout
;
133 umtx_op
= UMTX_OP_WAKE
;
140 return _umtx_op(uaddr
, umtx_op
, (uint32_t) val
, umtx_uaddr
,
144 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
145 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
147 return lttng_ust_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
150 #elif defined(__CYGWIN__)
153 * The futex_noasync compat code uses a weak symbol to share state across
154 * different shared object which is not possible on Windows with the
155 * Portable Executable format. Use the async compat code for both cases.
157 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
158 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
160 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
163 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
164 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
166 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
171 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
172 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
174 return lttng_ust_compat_futex_noasync(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
177 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
178 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
180 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
189 #endif /* _LTTNG_UST_FUTEX_H */
This page took 0.038118 seconds and 5 git commands to generate.