]>
Commit | Line | Data |
---|---|---|
3df6f22e | 1 | /* Low-level locking access to futex facilities. Stub version. |
581c785b | 2 | Copyright (C) 2014-2022 Free Software Foundation, Inc. |
3df6f22e RM |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library. If not, see | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
3df6f22e RM |
18 | |
19 | #ifndef _LOWLEVELLOCK_FUTEX_H | |
20 | #define _LOWLEVELLOCK_FUTEX_H 1 | |
21 | ||
b5803274 AZ |
22 | #ifndef __ASSEMBLER__ |
23 | # include <sysdep.h> | |
24 | # include <sysdep-cancel.h> | |
25 | # include <kernel-features.h> | |
26 | #endif | |
27 | ||
28 | #define FUTEX_WAIT 0 | |
29 | #define FUTEX_WAKE 1 | |
30 | #define FUTEX_REQUEUE 3 | |
31 | #define FUTEX_CMP_REQUEUE 4 | |
32 | #define FUTEX_WAKE_OP 5 | |
33 | #define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1) | |
34 | #define FUTEX_LOCK_PI 6 | |
35 | #define FUTEX_UNLOCK_PI 7 | |
36 | #define FUTEX_TRYLOCK_PI 8 | |
37 | #define FUTEX_WAIT_BITSET 9 | |
38 | #define FUTEX_WAKE_BITSET 10 | |
39 | #define FUTEX_WAIT_REQUEUE_PI 11 | |
40 | #define FUTEX_CMP_REQUEUE_PI 12 | |
8352b6df | 41 | #define FUTEX_LOCK_PI2 13 |
b5803274 AZ |
42 | #define FUTEX_PRIVATE_FLAG 128 |
43 | #define FUTEX_CLOCK_REALTIME 256 | |
44 | ||
45 | #define FUTEX_BITSET_MATCH_ANY 0xffffffff | |
46 | ||
47 | /* Values for 'private' parameter of locking macros. Yes, the | |
48 | definition seems to be backwards. But it is not. The bit will be | |
49 | reversed before passing to the system call. */ | |
50 | #define LLL_PRIVATE 0 | |
51 | #define LLL_SHARED FUTEX_PRIVATE_FLAG | |
52 | ||
53 | #ifndef __ASSEMBLER__ | |
c4ad8322 | 54 | # define __lll_private_flag(fl, private) \ |
b5803274 | 55 | (((fl) | FUTEX_PRIVATE_FLAG) ^ (private)) |
b5803274 | 56 | |
bc2eb932 | 57 | # define lll_futex_syscall(nargs, futexp, op, ...) \ |
b5803274 | 58 | ({ \ |
bc2eb932 | 59 | long int __ret = INTERNAL_SYSCALL (futex, nargs, futexp, op, \ |
b5803274 | 60 | __VA_ARGS__); \ |
bc2eb932 AZ |
61 | (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret)) \ |
62 | ? -INTERNAL_SYSCALL_ERRNO (__ret) : 0); \ | |
b5803274 | 63 | }) |
3df6f22e RM |
64 | |
65 | /* For most of these macros, the return value is never really used. | |
66 | Nevertheless, the protocol is that each one returns a negated errno | |
67 | code for failure or zero for success. (Note that the corresponding | |
68 | Linux system calls can sometimes return positive values for success | |
69 | cases too. We never use those values.) */ | |
70 | ||
71 | ||
72 | /* Wait while *FUTEXP == VAL for an lll_futex_wake call on FUTEXP. */ | |
b5803274 | 73 | # define lll_futex_wait(futexp, val, private) \ |
3df6f22e RM |
74 | lll_futex_timed_wait (futexp, val, NULL, private) |
75 | ||
b5803274 AZ |
76 | # define lll_futex_timed_wait(futexp, val, timeout, private) \ |
77 | lll_futex_syscall (4, futexp, \ | |
78 | __lll_private_flag (FUTEX_WAIT, private), \ | |
79 | val, timeout) | |
3df6f22e | 80 | |
99d01ffc MC |
81 | /* Verify whether the supplied clockid is supported by |
82 | lll_futex_clock_wait_bitset. */ | |
b5803274 AZ |
83 | # define lll_futex_supported_clockid(clockid) \ |
84 | ((clockid) == CLOCK_REALTIME || (clockid) == CLOCK_MONOTONIC) | |
85 | ||
3df6f22e | 86 | /* Wake up up to NR waiters on FUTEXP. */ |
b5803274 AZ |
87 | # define lll_futex_wake(futexp, nr, private) \ |
88 | lll_futex_syscall (4, futexp, \ | |
89 | __lll_private_flag (FUTEX_WAKE, private), nr, 0) | |
3df6f22e RM |
90 | |
91 | /* Wake up up to NR_WAKE waiters on FUTEXP. Move up to NR_MOVE of the | |
b5803274 AZ |
92 | rest from waiting on FUTEXP to waiting on MUTEX (a different futex). |
93 | Returns non-zero if error happened, zero if success. */ | |
94 | # define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val, private) \ | |
95 | lll_futex_syscall (6, futexp, \ | |
96 | __lll_private_flag (FUTEX_CMP_REQUEUE, private), \ | |
97 | nr_wake, nr_move, mutex, val) | |
98 | ||
99 | /* Wake up up to NR_WAKE waiters on FUTEXP and NR_WAKE2 on FUTEXP2. | |
100 | Returns non-zero if error happened, zero if success. */ | |
101 | # define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2, private) \ | |
102 | lll_futex_syscall (6, futexp, \ | |
103 | __lll_private_flag (FUTEX_WAKE_OP, private), \ | |
104 | nr_wake, nr_wake2, futexp2, \ | |
105 | FUTEX_OP_CLEAR_WAKE_IF_GT_ONE) | |
3df6f22e | 106 | |
3df6f22e | 107 | |
6b1472eb AZ |
108 | #define lll_futex_timed_unlock_pi(futexp, private) \ |
109 | lll_futex_syscall (4, futexp, \ | |
110 | __lll_private_flag (FUTEX_UNLOCK_PI, private), \ | |
111 | 0, 0) | |
3df6f22e | 112 | |
3df6f22e RM |
113 | /* Like lll_futex_requeue, but pairs with lll_futex_wait_requeue_pi |
114 | and inherits priority from the waiter. */ | |
b5803274 | 115 | # define lll_futex_cmp_requeue_pi(futexp, nr_wake, nr_move, mutex, \ |
3df6f22e | 116 | val, private) \ |
b5803274 AZ |
117 | lll_futex_syscall (6, futexp, \ |
118 | __lll_private_flag (FUTEX_CMP_REQUEUE_PI, \ | |
119 | private), \ | |
120 | nr_wake, nr_move, mutex, val) | |
3df6f22e | 121 | |
eb76e5b4 | 122 | /* Like lll_futex_wait, but acting as a cancellable entrypoint. */ |
b5803274 AZ |
123 | # define lll_futex_wait_cancel(futexp, val, private) \ |
124 | ({ \ | |
ce0b7961 | 125 | int __oldtype = LIBC_CANCEL_ASYNC (); \ |
b5803274 | 126 | long int __err = lll_futex_wait (futexp, val, LLL_SHARED); \ |
ce0b7961 | 127 | LIBC_CANCEL_RESET (__oldtype); \ |
b5803274 AZ |
128 | __err; \ |
129 | }) | |
eb76e5b4 AZ |
130 | |
131 | /* Like lll_futex_timed_wait, but acting as a cancellable entrypoint. */ | |
b5803274 AZ |
132 | # define lll_futex_timed_wait_cancel(futexp, val, timeout, private) \ |
133 | ({ \ | |
ce0b7961 | 134 | int __oldtype = LIBC_CANCEL_ASYNC (); \ |
b5803274 | 135 | long int __err = lll_futex_timed_wait (futexp, val, timeout, private); \ |
ce0b7961 | 136 | LIBC_CANCEL_RESET (__oldtype); \ |
b5803274 AZ |
137 | __err; \ |
138 | }) | |
139 | ||
140 | #endif /* !__ASSEMBLER__ */ | |
3df6f22e RM |
141 | |
142 | #endif /* lowlevellock-futex.h */ |