Make __strtod_internal tests type-generic
[glibc.git] / sysdeps / nptl / lowlevellock-futex.h
blobc205806300c41f8e816c0ca9a6a0829cae93d85d
1 /* Low-level locking access to futex facilities. Stub version.
2 Copyright (C) 2014-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <https://www.gnu.org/licenses/>. */
19 #ifndef _LOWLEVELLOCK_FUTEX_H
20 #define _LOWLEVELLOCK_FUTEX_H 1
22 #ifndef __ASSEMBLER__
23 # include <sysdep.h>
24 # include <kernel-features.h>
25 #endif
27 #define FUTEX_WAIT 0
28 #define FUTEX_WAKE 1
29 #define FUTEX_REQUEUE 3
30 #define FUTEX_CMP_REQUEUE 4
31 #define FUTEX_WAKE_OP 5
32 #define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
33 #define FUTEX_LOCK_PI 6
34 #define FUTEX_UNLOCK_PI 7
35 #define FUTEX_TRYLOCK_PI 8
36 #define FUTEX_WAIT_BITSET 9
37 #define FUTEX_WAKE_BITSET 10
38 #define FUTEX_WAIT_REQUEUE_PI 11
39 #define FUTEX_CMP_REQUEUE_PI 12
40 #define FUTEX_LOCK_PI2 13
41 #define FUTEX_PRIVATE_FLAG 128
42 #define FUTEX_CLOCK_REALTIME 256
44 #define FUTEX_BITSET_MATCH_ANY 0xffffffff
46 /* Values for 'private' parameter of locking macros. Yes, the
47 definition seems to be backwards. But it is not. The bit will be
48 reversed before passing to the system call. */
49 #define LLL_PRIVATE 0
50 #define LLL_SHARED FUTEX_PRIVATE_FLAG
52 #ifndef __ASSEMBLER__
53 # define __lll_private_flag(fl, private) \
54 (((fl) | FUTEX_PRIVATE_FLAG) ^ (private))
56 # define lll_futex_syscall(nargs, futexp, op, ...) \
57 ({ \
58 long int __ret = INTERNAL_SYSCALL (futex, nargs, futexp, op, \
59 __VA_ARGS__); \
60 (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret)) \
61 ? -INTERNAL_SYSCALL_ERRNO (__ret) : 0); \
64 /* For most of these macros, the return value is never really used.
65 Nevertheless, the protocol is that each one returns a negated errno
66 code for failure or zero for success. (Note that the corresponding
67 Linux system calls can sometimes return positive values for success
68 cases too. We never use those values.) */
71 /* Wait while *FUTEXP == VAL for an lll_futex_wake call on FUTEXP. */
72 # define lll_futex_wait(futexp, val, private) \
73 lll_futex_timed_wait (futexp, val, NULL, private)
75 # define lll_futex_timed_wait(futexp, val, timeout, private) \
76 lll_futex_syscall (4, futexp, \
77 __lll_private_flag (FUTEX_WAIT, private), \
78 val, timeout)
80 /* Verify whether the supplied clockid is supported by
81 lll_futex_clock_wait_bitset. */
82 # define lll_futex_supported_clockid(clockid) \
83 ((clockid) == CLOCK_REALTIME || (clockid) == CLOCK_MONOTONIC)
85 /* Wake up up to NR waiters on FUTEXP. */
86 # define lll_futex_wake(futexp, nr, private) \
87 lll_futex_syscall (4, futexp, \
88 __lll_private_flag (FUTEX_WAKE, private), nr, 0)
90 /* Wake up up to NR_WAKE waiters on FUTEXP. Move up to NR_MOVE of the
91 rest from waiting on FUTEXP to waiting on MUTEX (a different futex).
92 Returns non-zero if error happened, zero if success. */
93 # define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val, private) \
94 lll_futex_syscall (6, futexp, \
95 __lll_private_flag (FUTEX_CMP_REQUEUE, private), \
96 nr_wake, nr_move, mutex, val)
98 /* Wake up up to NR_WAKE waiters on FUTEXP and NR_WAKE2 on FUTEXP2.
99 Returns non-zero if error happened, zero if success. */
100 # define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2, private) \
101 lll_futex_syscall (6, futexp, \
102 __lll_private_flag (FUTEX_WAKE_OP, private), \
103 nr_wake, nr_wake2, futexp2, \
104 FUTEX_OP_CLEAR_WAKE_IF_GT_ONE)
107 #define lll_futex_timed_unlock_pi(futexp, private) \
108 lll_futex_syscall (4, futexp, \
109 __lll_private_flag (FUTEX_UNLOCK_PI, private), \
110 0, 0)
112 /* Like lll_futex_requeue, but pairs with lll_futex_wait_requeue_pi
113 and inherits priority from the waiter. */
114 # define lll_futex_cmp_requeue_pi(futexp, nr_wake, nr_move, mutex, \
115 val, private) \
116 lll_futex_syscall (6, futexp, \
117 __lll_private_flag (FUTEX_CMP_REQUEUE_PI, \
118 private), \
119 nr_wake, nr_move, mutex, val)
121 /* Like lll_futex_wait, but acting as a cancellable entrypoint. */
122 # define lll_futex_wait_cancel(futexp, val, private) \
123 ({ \
124 int __op = __lll_private_flag (FUTEX_WAIT, private); \
125 INTERNAL_SYSCALL_CANCEL (futex, futexp, __op, val, NULL); \
128 #endif /* !__ASSEMBLER__ */
130 #endif /* lowlevellock-futex.h */