]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/lowlevellock-futex.h
Remove IS_IN_rtld
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / lowlevellock-futex.h
1 /* Low-level locking access to futex facilities. Linux version.
2 Copyright (C) 2005-2014 Free Software Foundation, Inc.
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
17 <http://www.gnu.org/licenses/>. */
18
19 #ifndef _LOWLEVELLOCK_FUTEX_H
20 #define _LOWLEVELLOCK_FUTEX_H 1
21
22 #include <sysdep.h>
23 #include <tls.h>
24 #include <kernel-features.h>
25
26
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_PRIVATE_FLAG 128
41 #define FUTEX_CLOCK_REALTIME 256
42
43 #define FUTEX_BITSET_MATCH_ANY 0xffffffff
44
45 /* Values for 'private' parameter of locking macros. Yes, the
46 definition seems to be backwards. But it is not. The bit will be
47 reversed before passing to the system call. */
48 #define LLL_PRIVATE 0
49 #define LLL_SHARED FUTEX_PRIVATE_FLAG
50
51
52 #if !defined NOT_IN_libc || IS_IN (rtld)
53 /* In libc.so or ld.so all futexes are private. */
54 # ifdef __ASSUME_PRIVATE_FUTEX
55 # define __lll_private_flag(fl, private) \
56 ((fl) | FUTEX_PRIVATE_FLAG)
57 # else
58 # define __lll_private_flag(fl, private) \
59 ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex))
60 # endif
61 #else
62 # ifdef __ASSUME_PRIVATE_FUTEX
63 # define __lll_private_flag(fl, private) \
64 (((fl) | FUTEX_PRIVATE_FLAG) ^ (private))
65 # else
66 # define __lll_private_flag(fl, private) \
67 (__builtin_constant_p (private) \
68 ? ((private) == 0 \
69 ? ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex)) \
70 : (fl)) \
71 : ((fl) | (((private) ^ FUTEX_PRIVATE_FLAG) \
72 & THREAD_GETMEM (THREAD_SELF, header.private_futex))))
73 # endif
74 #endif
75
76 #define lll_futex_syscall(nargs, futexp, op, ...) \
77 ({ \
78 INTERNAL_SYSCALL_DECL (__err); \
79 long int __ret = INTERNAL_SYSCALL (futex, __err, nargs, futexp, op, \
80 __VA_ARGS__); \
81 (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret, __err)) \
82 ? -INTERNAL_SYSCALL_ERRNO (__ret, __err) : 0); \
83 })
84
85 #define lll_futex_wait(futexp, val, private) \
86 lll_futex_timed_wait (futexp, val, NULL, private)
87
88 #define lll_futex_timed_wait(futexp, val, timeout, private) \
89 lll_futex_syscall (4, futexp, \
90 __lll_private_flag (FUTEX_WAIT, private), \
91 val, timeout)
92
93 #define lll_futex_timed_wait_bitset(futexp, val, timeout, clockbit, private) \
94 lll_futex_syscall (6, futexp, \
95 __lll_private_flag (FUTEX_WAIT_BITSET | (clockbit), \
96 private), \
97 val, timeout, NULL /* Unused. */, \
98 FUTEX_BITSET_MATCH_ANY)
99
100 #define lll_futex_wake(futexp, nr, private) \
101 lll_futex_syscall (4, futexp, \
102 __lll_private_flag (FUTEX_WAKE, private), nr, 0)
103
104 /* Returns non-zero if error happened, zero if success. */
105 #define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val, private) \
106 lll_futex_syscall (6, futexp, \
107 __lll_private_flag (FUTEX_CMP_REQUEUE, private), \
108 nr_wake, nr_move, mutex, val)
109
110 /* Returns non-zero if error happened, zero if success. */
111 #define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2, private) \
112 lll_futex_syscall (6, futexp, \
113 __lll_private_flag (FUTEX_WAKE_OP, private), \
114 nr_wake, nr_wake2, futexp2, \
115 FUTEX_OP_CLEAR_WAKE_IF_GT_ONE)
116
117 /* Priority Inheritance support. */
118 #define lll_futex_wait_requeue_pi(futexp, val, mutex, private) \
119 lll_futex_timed_wait_requeue_pi (futexp, val, NULL, 0, mutex, private)
120
121 #define lll_futex_timed_wait_requeue_pi(futexp, val, timeout, clockbit, \
122 mutex, private) \
123 lll_futex_syscall (5, futexp, \
124 __lll_private_flag (FUTEX_WAIT_REQUEUE_PI \
125 | (clockbit), private), \
126 val, timeout, mutex)
127
128
129 #define lll_futex_cmp_requeue_pi(futexp, nr_wake, nr_move, mutex, \
130 val, private) \
131 lll_futex_syscall (6, futexp, \
132 __lll_private_flag (FUTEX_CMP_REQUEUE_PI, \
133 private), \
134 nr_wake, nr_move, mutex, val)
135
136
137 #endif /* lowlevellock-futex.h */