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
26 #include <urcu/config.h>
27 #include <urcu/syscall-compat.h>
41 * sys_futex compatibility header.
42 * Use *only* *either of* futex_noasync OR futex_async on a given address.
44 * futex_noasync cannot be executed in signal handlers, but ensures that
45 * it will be put in a wait queue even in compatibility mode.
47 * futex_async is signal-handler safe for the wakeup. It uses polling
48 * on the wait-side in compatibility mode.
50 * BEWARE: sys_futex() FUTEX_WAIT may return early if interrupted
54 extern int compat_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
55 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
);
56 extern int compat_futex_async(int32_t *uaddr
, int op
, int32_t val
,
57 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
);
59 #if (defined(__linux__) && defined(__NR_futex))
61 /* For backwards compat */
62 #define CONFIG_RCU_HAVE_FUTEX 1
66 #include <urcu/compiler.h>
67 #include <urcu/arch.h>
69 static inline int futex(int32_t *uaddr
, int op
, int32_t val
,
70 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
72 return syscall(__NR_futex
, uaddr
, op
, val
, timeout
,
76 static inline int futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
77 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
81 ret
= futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
82 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
84 * The fallback on ENOSYS is the async-safe version of
85 * the compat futex implementation, because the
86 * async-safe compat implementation allows being used
87 * concurrently with calls to futex(). Indeed, sys_futex
88 * FUTEX_WAIT, on some architectures (mips and parisc),
89 * within a given process, spuriously return ENOSYS due
90 * to signal restart bugs on some kernel versions.
92 return compat_futex_async(uaddr
, op
, val
, timeout
,
99 static inline int futex_async(int32_t *uaddr
, int op
, int32_t val
,
100 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
104 ret
= futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
105 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
106 return compat_futex_async(uaddr
, op
, val
, timeout
,
112 #elif defined(__FreeBSD__)
114 #include <sys/types.h>
115 #include <sys/umtx.h>
117 static inline int futex_async(int32_t *uaddr
, int op
, int32_t val
,
118 const struct timespec
*timeout
,
119 int32_t *uaddr2
__attribute__((unused
)),
120 int32_t val3
__attribute__((unused
)))
123 void *umtx_uaddr
= NULL
, *umtx_uaddr2
= NULL
;
124 struct _umtx_time umtx_timeout
= {
125 ._flags
= UMTX_ABSTIME
,
126 ._clockid
= CLOCK_MONOTONIC
,
131 /* On FreeBSD, a "u_int" is a 32-bit integer. */
132 umtx_op
= UMTX_OP_WAIT_UINT
;
133 if (timeout
!= NULL
) {
134 umtx_timeout
._timeout
= *timeout
;
135 umtx_uaddr
= (void *) sizeof(umtx_timeout
);
136 umtx_uaddr2
= (void *) &umtx_timeout
;
140 umtx_op
= UMTX_OP_WAKE
;
147 return _umtx_op(uaddr
, umtx_op
, (uint32_t) val
, umtx_uaddr
,
151 static inline int futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
152 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
154 return futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
157 #elif defined(__CYGWIN__)
160 * The futex_noasync compat code uses a weak symbol to share state across
161 * different shared object which is not possible on Windows with the
162 * Portable Executable format. Use the async compat code for both cases.
164 static inline int futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
165 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
167 return compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
170 static inline int futex_async(int32_t *uaddr
, int op
, int32_t val
,
171 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
173 return compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
178 static inline int futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
179 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
181 return compat_futex_noasync(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
184 static inline int futex_async(int32_t *uaddr
, int op
, int32_t val
,
185 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
187 return compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
196 #endif /* _URCU_FUTEX_H */
This page took 0.033448 seconds and 4 git commands to generate.