2.9
[glibc/nacl-glibc.git] / nptl / sysdeps / unix / sysv / linux / x86_64 / lowlevellock.h
blob2cd69a14cec30877b21e32d79d8fd4a1de65dd05
1 /* Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _LOWLEVELLOCK_H
21 #define _LOWLEVELLOCK_H 1
23 #ifndef __ASSEMBLER__
24 # include <time.h>
25 # include <sys/param.h>
26 # include <bits/pthreadtypes.h>
27 # include <kernel-features.h>
28 # include <tcb-offsets.h>
30 # ifndef LOCK_INSTR
31 # ifdef UP
32 # define LOCK_INSTR /* nothing */
33 # else
34 # define LOCK_INSTR "lock;"
35 # endif
36 # endif
37 #else
38 # ifndef LOCK
39 # ifdef UP
40 # define LOCK
41 # else
42 # define LOCK lock
43 # endif
44 # endif
45 #endif
47 #define SYS_futex 202
48 #define FUTEX_WAIT 0
49 #define FUTEX_WAKE 1
50 #define FUTEX_CMP_REQUEUE 4
51 #define FUTEX_WAKE_OP 5
52 #define FUTEX_LOCK_PI 6
53 #define FUTEX_UNLOCK_PI 7
54 #define FUTEX_TRYLOCK_PI 8
55 #define FUTEX_PRIVATE_FLAG 128
57 #define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
59 /* Values for 'private' parameter of locking macros. Yes, the
60 definition seems to be backwards. But it is not. The bit will be
61 reversed before passing to the system call. */
62 #define LLL_PRIVATE 0
63 #define LLL_SHARED FUTEX_PRIVATE_FLAG
65 #ifndef __ASSEMBLER__
67 #if !defined NOT_IN_libc || defined IS_IN_rtld
68 /* In libc.so or ld.so all futexes are private. */
69 # ifdef __ASSUME_PRIVATE_FUTEX
70 # define __lll_private_flag(fl, private) \
71 ((fl) | FUTEX_PRIVATE_FLAG)
72 # else
73 # define __lll_private_flag(fl, private) \
74 ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex))
75 # endif
76 #else
77 # ifdef __ASSUME_PRIVATE_FUTEX
78 # define __lll_private_flag(fl, private) \
79 (((fl) | FUTEX_PRIVATE_FLAG) ^ (private))
80 # else
81 # define __lll_private_flag(fl, private) \
82 (__builtin_constant_p (private) \
83 ? ((private) == 0 \
84 ? ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex)) \
85 : (fl)) \
86 : ({ unsigned int __fl = ((private) ^ FUTEX_PRIVATE_FLAG); \
87 asm ("andl %%fs:%P1, %0" : "+r" (__fl) \
88 : "i" (offsetof (struct pthread, header.private_futex))); \
89 __fl | (fl); }))
90 # endif
91 #endif
93 /* Initializer for lock. */
94 #define LLL_LOCK_INITIALIZER (0)
95 #define LLL_LOCK_INITIALIZER_LOCKED (1)
96 #define LLL_LOCK_INITIALIZER_WAITERS (2)
98 /* Delay in spinlock loop. */
99 #define BUSY_WAIT_NOP asm ("rep; nop")
102 #define LLL_STUB_UNWIND_INFO_START \
103 ".section .eh_frame,\"a\",@progbits\n" \
104 "7:\t" ".long 9f-8f # Length of Common Information Entry\n" \
105 "8:\t" ".long 0x0 # CIE Identifier Tag\n\t" \
106 ".byte 0x1 # CIE Version\n\t" \
107 ".ascii \"zR\\0\" # CIE Augmentation\n\t" \
108 ".uleb128 0x1 # CIE Code Alignment Factor\n\t" \
109 ".sleb128 -8 # CIE Data Alignment Factor\n\t" \
110 ".byte 0x10 # CIE RA Column\n\t" \
111 ".uleb128 0x1 # Augmentation size\n\t" \
112 ".byte 0x1b # FDE Encoding (pcrel sdata4)\n\t" \
113 ".byte 0x12 # DW_CFA_def_cfa_sf\n\t" \
114 ".uleb128 0x7\n\t" \
115 ".sleb128 16\n\t" \
116 ".align 8\n" \
117 "9:\t" ".long 23f-10f # FDE Length\n" \
118 "10:\t" ".long 10b-7b # FDE CIE offset\n\t" \
119 ".long 1b-. # FDE initial location\n\t" \
120 ".long 6b-1b # FDE address range\n\t" \
121 ".uleb128 0x0 # Augmentation size\n\t" \
122 ".byte 0x16 # DW_CFA_val_expression\n\t" \
123 ".uleb128 0x10\n\t" \
124 ".uleb128 12f-11f\n" \
125 "11:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
126 ".sleb128 4b-1b\n"
127 #define LLL_STUB_UNWIND_INFO_END \
128 ".byte 0x16 # DW_CFA_val_expression\n\t" \
129 ".uleb128 0x10\n\t" \
130 ".uleb128 14f-13f\n" \
131 "13:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
132 ".sleb128 4b-2b\n" \
133 "14:\t" ".byte 0x40 + (3b-2b) # DW_CFA_advance_loc\n\t" \
134 ".byte 0x0e # DW_CFA_def_cfa_offset\n\t" \
135 ".uleb128 0\n\t" \
136 ".byte 0x16 # DW_CFA_val_expression\n\t" \
137 ".uleb128 0x10\n\t" \
138 ".uleb128 16f-15f\n" \
139 "15:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
140 ".sleb128 4b-3b\n" \
141 "16:\t" ".byte 0x40 + (4b-3b-1) # DW_CFA_advance_loc\n\t" \
142 ".byte 0x0e # DW_CFA_def_cfa_offset\n\t" \
143 ".uleb128 128\n\t" \
144 ".byte 0x16 # DW_CFA_val_expression\n\t" \
145 ".uleb128 0x10\n\t" \
146 ".uleb128 20f-17f\n" \
147 "17:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
148 ".sleb128 19f-18f\n\t" \
149 ".byte 0x0d # DW_OP_const4s\n" \
150 "18:\t" ".4byte 4b-.\n\t" \
151 ".byte 0x1c # DW_OP_minus\n\t" \
152 ".byte 0x0d # DW_OP_const4s\n" \
153 "19:\t" ".4byte 24f-.\n\t" \
154 ".byte 0x22 # DW_OP_plus\n" \
155 "20:\t" ".byte 0x40 + (5b-4b+1) # DW_CFA_advance_loc\n\t" \
156 ".byte 0x13 # DW_CFA_def_cfa_offset_sf\n\t" \
157 ".sleb128 16\n\t" \
158 ".byte 0x16 # DW_CFA_val_expression\n\t" \
159 ".uleb128 0x10\n\t" \
160 ".uleb128 22f-21f\n" \
161 "21:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
162 ".sleb128 4b-5b\n" \
163 "22:\t" ".align 8\n" \
164 "23:\t" ".previous\n"
166 /* Unwind info for
167 1: leaq ..., %rdi
168 2: subq $128, %rsp
169 3: callq ...
170 4: addq $128, %rsp
171 5: jmp 24f
173 snippet. */
174 #define LLL_STUB_UNWIND_INFO_5 \
175 LLL_STUB_UNWIND_INFO_START \
176 "12:\t" ".byte 0x40 + (2b-1b) # DW_CFA_advance_loc\n\t" \
177 LLL_STUB_UNWIND_INFO_END
179 /* Unwind info for
180 1: leaq ..., %rdi
181 0: movq ..., %rdx
182 2: subq $128, %rsp
183 3: callq ...
184 4: addq $128, %rsp
185 5: jmp 24f
187 snippet. */
188 #define LLL_STUB_UNWIND_INFO_6 \
189 LLL_STUB_UNWIND_INFO_START \
190 "12:\t" ".byte 0x40 + (0b-1b) # DW_CFA_advance_loc\n\t" \
191 ".byte 0x16 # DW_CFA_val_expression\n\t" \
192 ".uleb128 0x10\n\t" \
193 ".uleb128 26f-25f\n" \
194 "25:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
195 ".sleb128 4b-0b\n" \
196 "26:\t" ".byte 0x40 + (2b-0b) # DW_CFA_advance_loc\n\t" \
197 LLL_STUB_UNWIND_INFO_END
200 #define lll_futex_wait(futex, val, private) \
201 lll_futex_timed_wait(futex, val, NULL, private)
204 #define lll_futex_timed_wait(futex, val, timeout, private) \
205 ({ \
206 register const struct timespec *__to __asm ("r10") = timeout; \
207 int __status; \
208 register __typeof (val) _val __asm ("edx") = (val); \
209 __asm __volatile ("syscall" \
210 : "=a" (__status) \
211 : "0" (SYS_futex), "D" (futex), \
212 "S" (__lll_private_flag (FUTEX_WAIT, private)), \
213 "d" (_val), "r" (__to) \
214 : "memory", "cc", "r11", "cx"); \
215 __status; \
219 #define lll_futex_wake(futex, nr, private) \
220 do { \
221 int __ignore; \
222 register __typeof (nr) _nr __asm ("edx") = (nr); \
223 __asm __volatile ("syscall" \
224 : "=a" (__ignore) \
225 : "0" (SYS_futex), "D" (futex), \
226 "S" (__lll_private_flag (FUTEX_WAKE, private)), \
227 "d" (_nr) \
228 : "memory", "cc", "r10", "r11", "cx"); \
229 } while (0)
232 /* NB: in the lll_trylock macro we simply return the value in %eax
233 after the cmpxchg instruction. In case the operation succeded this
234 value is zero. In case the operation failed, the cmpxchg instruction
235 has loaded the current value of the memory work which is guaranteed
236 to be nonzero. */
237 #if defined NOT_IN_libc || defined UP
238 # define __lll_trylock_asm LOCK_INSTR "cmpxchgl %2, %1"
239 #else
240 # define __lll_trylock_asm "cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
241 "je 0f\n\t" \
242 "lock; cmpxchgl %2, %1\n\t" \
243 "jmp 1f\n\t" \
244 "0:\tcmpxchgl %2, %1\n\t" \
245 "1:"
246 #endif
248 #define lll_trylock(futex) \
249 ({ int ret; \
250 __asm __volatile (__lll_trylock_asm \
251 : "=a" (ret), "=m" (futex) \
252 : "r" (LLL_LOCK_INITIALIZER_LOCKED), "m" (futex), \
253 "0" (LLL_LOCK_INITIALIZER) \
254 : "memory"); \
255 ret; })
257 #define lll_robust_trylock(futex, id) \
258 ({ int ret; \
259 __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
260 : "=a" (ret), "=m" (futex) \
261 : "r" (id), "m" (futex), "0" (LLL_LOCK_INITIALIZER) \
262 : "memory"); \
263 ret; })
265 #define lll_cond_trylock(futex) \
266 ({ int ret; \
267 __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
268 : "=a" (ret), "=m" (futex) \
269 : "r" (LLL_LOCK_INITIALIZER_WAITERS), \
270 "m" (futex), "0" (LLL_LOCK_INITIALIZER) \
271 : "memory"); \
272 ret; })
274 #if defined NOT_IN_libc || defined UP
275 # define __lll_lock_asm_start LOCK_INSTR "cmpxchgl %4, %2\n\t" \
276 "jnz 1f\n\t"
277 #else
278 # define __lll_lock_asm_start "cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
279 "je 0f\n\t" \
280 "lock; cmpxchgl %4, %2\n\t" \
281 "jnz 1f\n\t" \
282 "jmp 24f\n" \
283 "0:\tcmpxchgl %4, %2\n\t" \
284 "jnz 1f\n\t"
285 #endif
287 #define lll_lock(futex, private) \
288 (void) \
289 ({ int ignore1, ignore2, ignore3; \
290 if (__builtin_constant_p (private) && (private) == LLL_PRIVATE) \
291 __asm __volatile (__lll_lock_asm_start \
292 ".subsection 1\n\t" \
293 ".type _L_lock_%=, @function\n" \
294 "_L_lock_%=:\n" \
295 "1:\tleaq %2, %%rdi\n" \
296 "2:\tsubq $128, %%rsp\n" \
297 "3:\tcallq __lll_lock_wait_private\n" \
298 "4:\taddq $128, %%rsp\n" \
299 "5:\tjmp 24f\n" \
300 "6:\t.size _L_lock_%=, 6b-1b\n\t" \
301 ".previous\n" \
302 LLL_STUB_UNWIND_INFO_5 \
303 "24:" \
304 : "=S" (ignore1), "=&D" (ignore2), "=m" (futex), \
305 "=a" (ignore3) \
306 : "0" (1), "m" (futex), "3" (0) \
307 : "cx", "r11", "cc", "memory"); \
308 else \
309 __asm __volatile (__lll_lock_asm_start \
310 ".subsection 1\n\t" \
311 ".type _L_lock_%=, @function\n" \
312 "_L_lock_%=:\n" \
313 "1:\tleaq %2, %%rdi\n" \
314 "2:\tsubq $128, %%rsp\n" \
315 "3:\tcallq __lll_lock_wait\n" \
316 "4:\taddq $128, %%rsp\n" \
317 "5:\tjmp 24f\n" \
318 "6:\t.size _L_lock_%=, 6b-1b\n\t" \
319 ".previous\n" \
320 LLL_STUB_UNWIND_INFO_5 \
321 "24:" \
322 : "=S" (ignore1), "=D" (ignore2), "=m" (futex), \
323 "=a" (ignore3) \
324 : "1" (1), "m" (futex), "3" (0), "0" (private) \
325 : "cx", "r11", "cc", "memory"); \
326 }) \
328 #define lll_robust_lock(futex, id, private) \
329 ({ int result, ignore1, ignore2; \
330 __asm __volatile (LOCK_INSTR "cmpxchgl %4, %2\n\t" \
331 "jnz 1f\n\t" \
332 ".subsection 1\n\t" \
333 ".type _L_robust_lock_%=, @function\n" \
334 "_L_robust_lock_%=:\n" \
335 "1:\tleaq %2, %%rdi\n" \
336 "2:\tsubq $128, %%rsp\n" \
337 "3:\tcallq __lll_robust_lock_wait\n" \
338 "4:\taddq $128, %%rsp\n" \
339 "5:\tjmp 24f\n" \
340 "6:\t.size _L_robust_lock_%=, 6b-1b\n\t" \
341 ".previous\n" \
342 LLL_STUB_UNWIND_INFO_5 \
343 "24:" \
344 : "=S" (ignore1), "=D" (ignore2), "=m" (futex), \
345 "=a" (result) \
346 : "1" (id), "m" (futex), "3" (0), "0" (private) \
347 : "cx", "r11", "cc", "memory"); \
348 result; })
350 #define lll_cond_lock(futex, private) \
351 (void) \
352 ({ int ignore1, ignore2, ignore3; \
353 __asm __volatile (LOCK_INSTR "cmpxchgl %4, %2\n\t" \
354 "jnz 1f\n\t" \
355 ".subsection 1\n\t" \
356 ".type _L_cond_lock_%=, @function\n" \
357 "_L_cond_lock_%=:\n" \
358 "1:\tleaq %2, %%rdi\n" \
359 "2:\tsubq $128, %%rsp\n" \
360 "3:\tcallq __lll_lock_wait\n" \
361 "4:\taddq $128, %%rsp\n" \
362 "5:\tjmp 24f\n" \
363 "6:\t.size _L_cond_lock_%=, 6b-1b\n\t" \
364 ".previous\n" \
365 LLL_STUB_UNWIND_INFO_5 \
366 "24:" \
367 : "=S" (ignore1), "=D" (ignore2), "=m" (futex), \
368 "=a" (ignore3) \
369 : "1" (2), "m" (futex), "3" (0), "0" (private) \
370 : "cx", "r11", "cc", "memory"); \
373 #define lll_robust_cond_lock(futex, id, private) \
374 ({ int result, ignore1, ignore2; \
375 __asm __volatile (LOCK_INSTR "cmpxchgl %4, %2\n\t" \
376 "jnz 1f\n\t" \
377 ".subsection 1\n\t" \
378 ".type _L_robust_cond_lock_%=, @function\n" \
379 "_L_robust_cond_lock_%=:\n" \
380 "1:\tleaq %2, %%rdi\n" \
381 "2:\tsubq $128, %%rsp\n" \
382 "3:\tcallq __lll_robust_lock_wait\n" \
383 "4:\taddq $128, %%rsp\n" \
384 "5:\tjmp 24f\n" \
385 "6:\t.size _L_robust_cond_lock_%=, 6b-1b\n\t" \
386 ".previous\n" \
387 LLL_STUB_UNWIND_INFO_5 \
388 "24:" \
389 : "=S" (ignore1), "=D" (ignore2), "=m" (futex), \
390 "=a" (result) \
391 : "1" (id | FUTEX_WAITERS), "m" (futex), "3" (0), \
392 "0" (private) \
393 : "cx", "r11", "cc", "memory"); \
394 result; })
396 #define lll_timedlock(futex, timeout, private) \
397 ({ int result, ignore1, ignore2, ignore3; \
398 __asm __volatile (LOCK_INSTR "cmpxchgl %1, %4\n\t" \
399 "jnz 1f\n\t" \
400 ".subsection 1\n\t" \
401 ".type _L_timedlock_%=, @function\n" \
402 "_L_timedlock_%=:\n" \
403 "1:\tleaq %4, %%rdi\n" \
404 "0:\tmovq %8, %%rdx\n" \
405 "2:\tsubq $128, %%rsp\n" \
406 "3:\tcallq __lll_timedlock_wait\n" \
407 "4:\taddq $128, %%rsp\n" \
408 "5:\tjmp 24f\n" \
409 "6:\t.size _L_timedlock_%=, 6b-1b\n\t" \
410 ".previous\n" \
411 LLL_STUB_UNWIND_INFO_6 \
412 "24:" \
413 : "=a" (result), "=D" (ignore1), "=S" (ignore2), \
414 "=&d" (ignore3), "=m" (futex) \
415 : "0" (0), "1" (1), "m" (futex), "m" (timeout), \
416 "2" (private) \
417 : "memory", "cx", "cc", "r10", "r11"); \
418 result; })
420 #define lll_robust_timedlock(futex, timeout, id, private) \
421 ({ int result, ignore1, ignore2, ignore3; \
422 __asm __volatile (LOCK_INSTR "cmpxchgl %1, %4\n\t" \
423 "jnz 1f\n\t" \
424 ".subsection 1\n\t" \
425 ".type _L_robust_timedlock_%=, @function\n" \
426 "_L_robust_timedlock_%=:\n" \
427 "1:\tleaq %4, %%rdi\n" \
428 "0:\tmovq %8, %%rdx\n" \
429 "2:\tsubq $128, %%rsp\n" \
430 "3:\tcallq __lll_robust_timedlock_wait\n" \
431 "4:\taddq $128, %%rsp\n" \
432 "5:\tjmp 24f\n" \
433 "6:\t.size _L_robust_timedlock_%=, 6b-1b\n\t" \
434 ".previous\n" \
435 LLL_STUB_UNWIND_INFO_6 \
436 "24:" \
437 : "=a" (result), "=D" (ignore1), "=S" (ignore2), \
438 "=&d" (ignore3), "=m" (futex) \
439 : "0" (0), "1" (id), "m" (futex), "m" (timeout), \
440 "2" (private) \
441 : "memory", "cx", "cc", "r10", "r11"); \
442 result; })
444 #if defined NOT_IN_libc || defined UP
445 # define __lll_unlock_asm_start LOCK_INSTR "decl %0\n\t" \
446 "jne 1f\n\t"
447 #else
448 # define __lll_unlock_asm_start "cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
449 "je 0f\n\t" \
450 "lock; decl %0\n\t" \
451 "jne 1f\n\t" \
452 "jmp 24f\n\t" \
453 "0:\tdecl %0\n\t" \
454 "jne 1f\n\t"
455 #endif
457 #define lll_unlock(futex, private) \
458 (void) \
459 ({ int ignore; \
460 if (__builtin_constant_p (private) && (private) == LLL_PRIVATE) \
461 __asm __volatile (__lll_unlock_asm_start \
462 ".subsection 1\n\t" \
463 ".type _L_unlock_%=, @function\n" \
464 "_L_unlock_%=:\n" \
465 "1:\tleaq %0, %%rdi\n" \
466 "2:\tsubq $128, %%rsp\n" \
467 "3:\tcallq __lll_unlock_wake_private\n" \
468 "4:\taddq $128, %%rsp\n" \
469 "5:\tjmp 24f\n" \
470 "6:\t.size _L_unlock_%=, 6b-1b\n\t" \
471 ".previous\n" \
472 LLL_STUB_UNWIND_INFO_5 \
473 "24:" \
474 : "=m" (futex), "=&D" (ignore) \
475 : "m" (futex) \
476 : "ax", "cx", "r11", "cc", "memory"); \
477 else \
478 __asm __volatile (__lll_unlock_asm_start \
479 ".subsection 1\n\t" \
480 ".type _L_unlock_%=, @function\n" \
481 "_L_unlock_%=:\n" \
482 "1:\tleaq %0, %%rdi\n" \
483 "2:\tsubq $128, %%rsp\n" \
484 "3:\tcallq __lll_unlock_wake\n" \
485 "4:\taddq $128, %%rsp\n" \
486 "5:\tjmp 24f\n" \
487 "6:\t.size _L_unlock_%=, 6b-1b\n\t" \
488 ".previous\n" \
489 LLL_STUB_UNWIND_INFO_5 \
490 "24:" \
491 : "=m" (futex), "=&D" (ignore) \
492 : "m" (futex), "S" (private) \
493 : "ax", "cx", "r11", "cc", "memory"); \
496 #define lll_robust_unlock(futex, private) \
497 do \
499 int ignore; \
500 __asm __volatile (LOCK_INSTR "andl %2, %0\n\t" \
501 "jne 1f\n\t" \
502 ".subsection 1\n\t" \
503 ".type _L_robust_unlock_%=, @function\n" \
504 "_L_robust_unlock_%=:\n" \
505 "1:\tleaq %0, %%rdi\n" \
506 "2:\tsubq $128, %%rsp\n" \
507 "3:\tcallq __lll_unlock_wake\n" \
508 "4:\taddq $128, %%rsp\n" \
509 "5:\tjmp 24f\n" \
510 "6:\t.size _L_robust_unlock_%=, 6b-1b\n\t" \
511 ".previous\n" \
512 LLL_STUB_UNWIND_INFO_5 \
513 "24:" \
514 : "=m" (futex), "=&D" (ignore) \
515 : "i" (FUTEX_WAITERS), "m" (futex), \
516 "S" (private) \
517 : "ax", "cx", "r11", "cc", "memory"); \
519 while (0)
521 #define lll_robust_dead(futex, private) \
522 do \
524 int ignore; \
525 __asm __volatile (LOCK_INSTR "orl %3, (%2)\n\t" \
526 "syscall" \
527 : "=m" (futex), "=a" (ignore) \
528 : "D" (&(futex)), "i" (FUTEX_OWNER_DIED), \
529 "S" (__lll_private_flag (FUTEX_WAKE, private)), \
530 "1" (__NR_futex), "d" (1) \
531 : "cx", "r11", "cc", "memory"); \
533 while (0)
535 /* Returns non-zero if error happened, zero if success. */
536 #define lll_futex_requeue(ftx, nr_wake, nr_move, mutex, val, private) \
537 ({ int __res; \
538 register int __nr_move __asm ("r10") = nr_move; \
539 register void *__mutex __asm ("r8") = mutex; \
540 register int __val __asm ("r9") = val; \
541 __asm __volatile ("syscall" \
542 : "=a" (__res) \
543 : "0" (__NR_futex), "D" ((void *) ftx), \
544 "S" (__lll_private_flag (FUTEX_CMP_REQUEUE, \
545 private)), "d" (nr_wake), \
546 "r" (__nr_move), "r" (__mutex), "r" (__val) \
547 : "cx", "r11", "cc", "memory"); \
548 __res < 0; })
550 #define lll_islocked(futex) \
551 (futex != LLL_LOCK_INITIALIZER)
554 /* The kernel notifies a process with uses CLONE_CLEARTID via futex
555 wakeup when the clone terminates. The memory location contains the
556 thread ID while the clone is running and is reset to zero
557 afterwards.
559 The macro parameter must not have any side effect. */
560 #define lll_wait_tid(tid) \
561 do { \
562 int __ignore; \
563 register __typeof (tid) _tid asm ("edx") = (tid); \
564 if (_tid != 0) \
565 __asm __volatile ("xorq %%r10, %%r10\n\t" \
566 "1:\tmovq %2, %%rax\n\t" \
567 "syscall\n\t" \
568 "cmpl $0, (%%rdi)\n\t" \
569 "jne 1b" \
570 : "=&a" (__ignore) \
571 : "S" (FUTEX_WAIT), "i" (SYS_futex), "D" (&tid), \
572 "d" (_tid) \
573 : "memory", "cc", "r10", "r11", "cx"); \
574 } while (0)
576 extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
577 attribute_hidden;
578 #define lll_timedwait_tid(tid, abstime) \
579 ({ \
580 int __result = 0; \
581 if (tid != 0) \
583 if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) \
584 __result = EINVAL; \
585 else \
586 __result = __lll_timedwait_tid (&tid, abstime); \
588 __result; })
590 #endif /* !__ASSEMBLER__ */
592 #endif /* lowlevellock.h */