1 /* Copyright (C) 2002, 2003, 2004, 2006 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
21 #include <pthread-errnos.h>
22 #include <lowlevelrobustlock.h>
34 #define SYS_gettimeofday __NR_gettimeofday
38 #define FUTEX_WAITERS 0x80000000
39 #define FUTEX_OWNER_DIED 0x40000000
42 .globl __lll_robust_mutex_lock_wait
43 .type __lll_robust_mutex_lock_wait,@function
44 .hidden __lll_robust_mutex_lock_wait
46 __lll_robust_mutex_lock_wait:
49 cfi_adjust_cfa_offset(4)
51 cfi_adjust_cfa_offset(4)
53 cfi_adjust_cfa_offset(4)
59 xorl %esi, %esi /* No timeout. */
60 xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
63 orl $FUTEX_WAITERS, %edx
65 testl $FUTEX_OWNER_DIED, %eax
68 cmpl %edx, %eax /* NB: %edx == 2 */
75 1: movl $SYS_futex, %eax
84 orl $FUTEX_WAITERS, %edx
91 cfi_adjust_cfa_offset(-4)
94 cfi_adjust_cfa_offset(-4)
97 cfi_adjust_cfa_offset(-4)
101 .size __lll_robust_mutex_lock_wait,.-__lll_robust_mutex_lock_wait
104 .globl __lll_robust_mutex_timedlock_wait
105 .type __lll_robust_mutex_timedlock_wait,@function
106 .hidden __lll_robust_mutex_timedlock_wait
108 __lll_robust_mutex_timedlock_wait:
110 /* Check for a valid timeout value. */
111 cmpl $1000000000, 4(%edx)
115 cfi_adjust_cfa_offset(4)
117 cfi_adjust_cfa_offset(4)
119 cfi_adjust_cfa_offset(4)
121 cfi_adjust_cfa_offset(4)
123 cfi_offset(%esi, -12)
124 cfi_offset(%ebx, -16)
125 cfi_offset(%ebp, -20)
127 /* Stack frame for the timespec and timeval structs. */
129 cfi_adjust_cfa_offset(12)
134 1: movl %eax, 8(%esp)
136 /* Get current time. */
139 movl $SYS_gettimeofday, %eax
142 /* Compute relative timeout. */
145 mul %edx /* Milli seconds to nano seconds. */
151 addl $1000000000, %edx
154 js 8f /* Time is already up. */
156 /* Store relative timeout. */
164 orl $FUTEX_WAITERS, %edx
166 testl $FUTEX_OWNER_DIED, %eax
173 cmpxchgl %edx, (%ebx)
174 movl $0, %ecx /* Must use mov to avoid changing cc. */
180 xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
181 movl $SYS_futex, %eax
191 orl $FUTEX_WAITERS, %edx
193 cmpxchgl %edx, (%ebx)
197 cfi_adjust_cfa_offset(-12)
199 cfi_adjust_cfa_offset(-4)
202 cfi_adjust_cfa_offset(-4)
205 cfi_adjust_cfa_offset(-4)
208 cfi_adjust_cfa_offset(-4)
212 3: movl $EINVAL, %eax
215 cfi_adjust_cfa_offset(28)
217 cfi_offset(%esi, -12)
218 cfi_offset(%ebx, -16)
219 cfi_offset(%ebp, -20)
220 /* Check whether the time expired. */
221 7: cmpl $-ETIMEDOUT, %ecx
224 8: movl $ETIMEDOUT, %eax
227 .size __lll_robust_mutex_timedlock_wait,.-__lll_robust_mutex_timedlock_wait