1 /* Copyright (C) 2003-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
19 #include <pthread-errnos.h>
20 #include <lowlevellock.h>
21 #include <lowlevelrobustlock.h>
22 #include <kernel-features.h>
23 #include "lowlevel-atomic.h"
27 #define FUTEX_WAITERS 0x80000000
28 #define FUTEX_OWNER_DIED 0x40000000
30 #ifdef __ASSUME_PRIVATE_FUTEX
31 # define LOAD_FUTEX_WAIT(reg,tmp,tmp2) \
32 mov #(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), tmp; \
37 # define LOAD_FUTEX_WAIT(reg,tmp,tmp2) \
43 mov #FUTEX_PRIVATE_FLAG, tmp ; \
44 99: .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE ; \
45 98: extu.b tmp, tmp ; \
49 # define LOAD_FUTEX_WAIT(reg,tmp,tmp2) \
55 mov #FUTEX_PRIVATE_FLAG, tmp ; \
56 99: .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE ; \
57 98: extu.b tmp, tmp ; \
60 mov #FUTEX_WAIT, tmp ; \
65 .globl __lll_robust_lock_wait
66 .type __lll_robust_lock_wait,@function
67 .hidden __lll_robust_lock_wait
70 __lll_robust_lock_wait:
72 cfi_adjust_cfa_offset(4)
73 cfi_rel_offset (r8, 0)
75 mov #0, r7 /* No timeout. */
77 LOAD_FUTEX_WAIT (r5, r0, r1)
81 mov.l .L_FUTEX_WAITERS, r0
83 shlr r0 /* r0 = FUTEX_OWNER_DIED */
89 CMPXCHG (r4, @r8, r6, r2)
111 CMPXCHG (r3, @r8, r6, r4)
117 cfi_adjust_cfa_offset (-4)
126 .word TID - TLS_PRE_TCB_SIZE
127 .size __lll_robust_lock_wait,.-__lll_robust_lock_wait
130 .globl __lll_robust_timedlock_wait
131 .type __lll_robust_timedlock_wait,@function
132 .hidden __lll_robust_timedlock_wait
135 __lll_robust_timedlock_wait:
136 /* Check for a valid timeout value. */
145 cfi_adjust_cfa_offset(4)
146 cfi_rel_offset (r11, 0)
148 cfi_adjust_cfa_offset(4)
149 cfi_rel_offset (r10, 0)
151 cfi_adjust_cfa_offset(4)
152 cfi_rel_offset (r9, 0)
154 cfi_adjust_cfa_offset(4)
155 cfi_rel_offset (r8, 0)
161 /* Stack frame for the timespec and timeval structs. */
163 cfi_adjust_cfa_offset(8)
166 /* Get current time. */
169 mov #__NR_gettimeofday, r3
173 /* Compute relative timeout. */
176 dmulu.l r0, r1 /* Micro seconds to nano seconds. */
190 bf 8f /* Time is already up. */
192 mov.l r2, @r15 /* Store relative timeout. */
196 mov.l .L_FUTEX_WAITERS2, r0
198 shlr r0 /* r0 = FUTEX_OWNER_DIED */
204 CMPXCHG (r4, @r8, r6, r2)
211 LOAD_FUTEX_WAIT (r5, r0, r1)
232 CMPXCHG (r3, @r8, r4, r10)
239 cfi_adjust_cfa_offset (-8)
241 cfi_adjust_cfa_offset (-4)
244 cfi_adjust_cfa_offset (-4)
247 cfi_adjust_cfa_offset (-4)
251 /* Omit CFI for restore in delay slot. */
255 /* Check whether the time expired. */
275 .word TID - TLS_PRE_TCB_SIZE
278 .size __lll_robust_timedlock_wait,.-__lll_robust_timedlock_wait