1 /* Copyright (C) 2003, 2004, 2005, 2006, 2007
2 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <pthread-errnos.h>
22 #include <lowlevellock.h>
23 #include <lowlevelrobustlock.h>
24 #include <kernel-features.h>
25 #include "lowlevel-atomic.h"
29 #define FUTEX_WAITERS 0x80000000
30 #define FUTEX_OWNER_DIED 0x40000000
32 #ifdef __ASSUME_PRIVATE_FUTEX
33 # define LOAD_FUTEX_WAIT(reg,tmp,tmp2) \
34 mov #(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), tmp; \
39 # define LOAD_FUTEX_WAIT(reg,tmp,tmp2) \
45 mov #FUTEX_PRIVATE_FLAG, tmp ; \
46 99: .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE ; \
47 98: extu.b tmp, tmp ; \
51 # define LOAD_FUTEX_WAIT(reg,tmp,tmp2) \
57 mov #FUTEX_PRIVATE_FLAG, tmp ; \
58 99: .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE ; \
59 98: extu.b tmp, tmp ; \
62 mov #FUTEX_WAIT, tmp ; \
67 .globl __lll_robust_lock_wait
68 .type __lll_robust_lock_wait,@function
69 .hidden __lll_robust_lock_wait
72 __lll_robust_lock_wait:
74 cfi_adjust_cfa_offset(4)
75 cfi_rel_offset (r8, 0)
77 mov #0, r7 /* No timeout. */
79 LOAD_FUTEX_WAIT (r5, r0, r1)
83 mov.l .L_FUTEX_WAITERS, r0
85 shlr r0 /* r0 = FUTEX_OWNER_DIED */
91 CMPXCHG (r4, @r8, r6, r2)
113 CMPXCHG (r3, @r8, r6, r4)
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. */
143 cfi_adjust_cfa_offset(4)
144 cfi_rel_offset (r11, 0)
146 cfi_adjust_cfa_offset(4)
147 cfi_rel_offset (r10, 0)
149 cfi_adjust_cfa_offset(4)
150 cfi_rel_offset (r9, 0)
152 cfi_adjust_cfa_offset(4)
153 cfi_rel_offset (r8, 0)
159 /* Stack frame for the timespec and timeval structs. */
161 cfi_adjust_cfa_offset(8)
164 /* Get current time. */
167 mov #__NR_gettimeofday, r3
171 /* Compute relative timeout. */
174 dmulu.l r0, r1 /* Micro seconds to nano seconds. */
188 bf 8f /* Time is already up. */
190 mov.l r2, @r15 /* Store relative timeout. */
194 mov.l .L_FUTEX_WAITERS2, r0
196 shlr r0 /* r0 = FUTEX_OWNER_DIED */
202 CMPXCHG (r4, @r8, r6, r2)
209 LOAD_FUTEX_WAIT (r5, r0, r1)
230 CMPXCHG (r3, @r8, r4, r10)
243 /* Check whether the time expired. */
261 .word TID - TLS_PRE_TCB_SIZE
264 .size __lll_robust_timedlock_wait,.-__lll_robust_timedlock_wait