Fix: handle sys_futex() FUTEX_WAIT interrupted by signal
[urcu.git] / urcu / futex.h
CommitLineData
49617de1
MD
1#ifndef _URCU_FUTEX_H
2#define _URCU_FUTEX_H
3
4/*
5 * urcu-futex.h
6 *
7 * Userspace RCU - sys_futex/compat_futex header.
8 *
3282a76b
MD
9 * Copyright 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
49617de1
MD
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.
15 *
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.
20 *
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
24 */
25
26#include <urcu/config.h>
6d841bc2 27#include <stdint.h>
49617de1 28
36bc70a8
MD
29#ifdef __cplusplus
30extern "C" {
31#endif
32
49617de1
MD
33#define FUTEX_WAIT 0
34#define FUTEX_WAKE 1
35
36/*
37 * sys_futex compatibility header.
38 * Use *only* *either of* futex_noasync OR futex_async on a given address.
39 *
40 * futex_noasync cannot be executed in signal handlers, but ensures that
41 * it will be put in a wait queue even in compatibility mode.
42 *
43 * futex_async is signal-handler safe for the wakeup. It uses polling
44 * on the wait-side in compatibility mode.
b0a841b4
MD
45 *
46 * BEWARE: sys_futex() FUTEX_WAIT may return early if interrupted
47 * (returns EINTR).
49617de1
MD
48 */
49
02be5561 50#ifdef CONFIG_RCU_HAVE_FUTEX
9ba261bd 51#include <urcu/syscall-compat.h>
49617de1
MD
52#define futex(...) syscall(__NR_futex, __VA_ARGS__)
53#define futex_noasync(uaddr, op, val, timeout, uaddr2, val3) \
54 futex(uaddr, op, val, timeout, uaddr2, val3)
55#define futex_async(uaddr, op, val, timeout, uaddr2, val3) \
56 futex(uaddr, op, val, timeout, uaddr2, val3)
57#else
6d841bc2
MD
58extern int compat_futex_noasync(int32_t *uaddr, int op, int32_t val,
59 const struct timespec *timeout, int32_t *uaddr2, int32_t val3);
49617de1
MD
60#define futex_noasync(uaddr, op, val, timeout, uaddr2, val3) \
61 compat_futex_noasync(uaddr, op, val, timeout, uaddr2, val3)
6d841bc2
MD
62extern int compat_futex_async(int32_t *uaddr, int op, int32_t val,
63 const struct timespec *timeout, int32_t *uaddr2, int32_t val3);
49617de1
MD
64#define futex_async(uaddr, op, val, timeout, uaddr2, val3) \
65 compat_futex_async(uaddr, op, val, timeout, uaddr2, val3)
66#endif
67
36bc70a8
MD
68#ifdef __cplusplus
69}
70#endif
71
49617de1 72#endif /* _URCU_FUTEX_H */
This page took 0.032704 seconds and 4 git commands to generate.