Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / unix / sysv / linux / i386 / lowlevellock-futex.h
blobf08b5b8497f9c70750a1cd9e4d9098d63234b0d0
1 /* Low-level locking access to futex facilities. Linux/i386 version.
2 Copyright (C) 2014-2015 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 <http://www.gnu.org/licenses/>. */
19 #ifndef _LOWLEVELLOCK_FUTEX_H
20 #define _LOWLEVELLOCK_FUTEX_H 1
22 #define FUTEX_WAIT 0
23 #define FUTEX_WAKE 1
24 #define FUTEX_CMP_REQUEUE 4
25 #define FUTEX_WAKE_OP 5
26 #define FUTEX_LOCK_PI 6
27 #define FUTEX_UNLOCK_PI 7
28 #define FUTEX_TRYLOCK_PI 8
29 #define FUTEX_WAIT_BITSET 9
30 #define FUTEX_WAKE_BITSET 10
31 #define FUTEX_WAIT_REQUEUE_PI 11
32 #define FUTEX_CMP_REQUEUE_PI 12
33 #define FUTEX_PRIVATE_FLAG 128
34 #define FUTEX_CLOCK_REALTIME 256
36 #define FUTEX_BITSET_MATCH_ANY 0xffffffff
38 #define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
40 /* Values for 'private' parameter of locking macros. Yes, the
41 definition seems to be backwards. But it is not. The bit will be
42 reversed before passing to the system call. */
43 #define LLL_PRIVATE 0
44 #define LLL_SHARED FUTEX_PRIVATE_FLAG
47 #if IS_IN (libc) || IS_IN (rtld)
48 /* In libc.so or ld.so all futexes are private. */
49 # ifdef __ASSUME_PRIVATE_FUTEX
50 # define __lll_private_flag(fl, private) \
51 ((fl) | FUTEX_PRIVATE_FLAG)
52 # else
53 # define __lll_private_flag(fl, private) \
54 ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex))
55 # endif
56 #else
57 # ifdef __ASSUME_PRIVATE_FUTEX
58 # define __lll_private_flag(fl, private) \
59 (((fl) | FUTEX_PRIVATE_FLAG) ^ (private))
60 # else
61 # define __lll_private_flag(fl, private) \
62 (__builtin_constant_p (private) \
63 ? ((private) == 0 \
64 ? ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex)) \
65 : (fl)) \
66 : ({ unsigned int __fl = ((private) ^ FUTEX_PRIVATE_FLAG); \
67 asm ("andl %%gs:%P1, %0" : "+r" (__fl) \
68 : "i" (offsetof (struct pthread, header.private_futex))); \
69 __fl | (fl); }))
70 # endif
71 #endif
74 #ifndef __ASSEMBLER__
76 /* To avoid naming conflicts with lowlevellock.h, use a different prefix
77 here. */
78 #ifdef PIC
79 # define LLLF_EBX_LOAD "xchgl %2, %%ebx\n"
80 # define LLLF_EBX_REG "D"
81 #else
82 # define LLLF_EBX_LOAD
83 # define LLLF_EBX_REG "b"
84 #endif
86 #ifdef I386_USE_SYSENTER
87 # ifdef SHARED
88 # define LLLF_ENTER_KERNEL "call *%%gs:%P6\n\t"
89 # else
90 # define LLLF_ENTER_KERNEL "call *_dl_sysinfo\n\t"
91 # endif
92 #else
93 # define LLLF_ENTER_KERNEL "int $0x80\n\t"
94 #endif
97 #define lll_futex_wait(futex, val, private) \
98 lll_futex_timed_wait (futex, val, NULL, private)
101 #define lll_futex_timed_wait(futex, val, timeout, private) \
102 ({ \
103 int __status; \
104 register __typeof (val) _val asm ("edx") = (val); \
105 __asm __volatile (LLLF_EBX_LOAD \
106 LLLF_ENTER_KERNEL \
107 LLLF_EBX_LOAD \
108 : "=a" (__status) \
109 : "0" (SYS_futex), LLLF_EBX_REG (futex), "S" (timeout), \
110 "c" (__lll_private_flag (FUTEX_WAIT, private)), \
111 "d" (_val), "i" (offsetof (tcbhead_t, sysinfo)) \
112 : "memory"); \
113 __status; \
117 #define lll_futex_wake(futex, nr, private) \
118 ({ \
119 int __status; \
120 register __typeof (nr) _nr asm ("edx") = (nr); \
121 LIBC_PROBE (lll_futex_wake, 3, futex, nr, private); \
122 __asm __volatile (LLLF_EBX_LOAD \
123 LLLF_ENTER_KERNEL \
124 LLLF_EBX_LOAD \
125 : "=a" (__status) \
126 : "0" (SYS_futex), LLLF_EBX_REG (futex), \
127 "c" (__lll_private_flag (FUTEX_WAKE, private)), \
128 "d" (_nr), \
129 "i" (0) /* phony, to align next arg's number */, \
130 "i" (offsetof (tcbhead_t, sysinfo))); \
131 __status; \
135 #endif /* !__ASSEMBLER__ */
137 #endif /* lowlevellock-futex.h */