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
21 #include <pthread-errnos.h>
22 #include <lowlevellock.h>
23 #include <lowlevelrobustlock.h>
24 #include <kernel-features.h>
28 #define FUTEX_WAITERS 0x80000000
29 #define FUTEX_OWNER_DIED 0x40000000
31 #ifdef __ASSUME_PRIVATE_FUTEX
32 # define LOAD_FUTEX_WAIT(reg) \
33 xorl $(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
36 # define LOAD_FUTEX_WAIT(reg) \
37 xorl $FUTEX_PRIVATE_FLAG, reg ; \
38 andl %gs:PRIVATE_FUTEX, reg
40 # define LOAD_FUTEX_WAIT(reg) \
41 xorl $FUTEX_PRIVATE_FLAG, reg ; \
42 andl %gs:PRIVATE_FUTEX, reg ; \
47 .globl __lll_robust_lock_wait
48 .type __lll_robust_lock_wait,@function
49 .hidden __lll_robust_lock_wait
51 __lll_robust_lock_wait:
54 cfi_adjust_cfa_offset(4)
56 cfi_adjust_cfa_offset(4)
58 cfi_adjust_cfa_offset(4)
64 xorl %esi, %esi /* No timeout. */
65 LOAD_FUTEX_WAIT (%ecx)
68 orl $FUTEX_WAITERS, %edx
70 testl $FUTEX_OWNER_DIED, %eax
73 cmpl %edx, %eax /* NB: %edx == 2 */
80 1: movl $SYS_futex, %eax
89 orl $FUTEX_WAITERS, %edx
96 cfi_adjust_cfa_offset(-4)
99 cfi_adjust_cfa_offset(-4)
102 cfi_adjust_cfa_offset(-4)
106 .size __lll_robust_lock_wait,.-__lll_robust_lock_wait
109 .globl __lll_robust_timedlock_wait
110 .type __lll_robust_timedlock_wait,@function
111 .hidden __lll_robust_timedlock_wait
113 __lll_robust_timedlock_wait:
115 /* Check for a valid timeout value. */
116 cmpl $1000000000, 4(%edx)
120 cfi_adjust_cfa_offset(4)
122 cfi_adjust_cfa_offset(4)
124 cfi_adjust_cfa_offset(4)
126 cfi_adjust_cfa_offset(4)
128 cfi_offset(%esi, -12)
129 cfi_offset(%ebx, -16)
130 cfi_offset(%ebp, -20)
132 /* Stack frame for the timespec and timeval structs. */
134 cfi_adjust_cfa_offset(12)
139 1: movl %eax, 8(%esp)
141 /* Get current time. */
144 movl $__NR_gettimeofday, %eax
147 /* Compute relative timeout. */
150 mul %edx /* Milli seconds to nano seconds. */
156 addl $1000000000, %edx
159 js 8f /* Time is already up. */
161 /* Store relative timeout. */
169 orl $FUTEX_WAITERS, %edx
171 testl $FUTEX_OWNER_DIED, %eax
178 cmpxchgl %edx, (%ebx)
179 movl $0, %ecx /* Must use mov to avoid changing cc. */
186 LOAD_FUTEX_WAIT (%ecx)
187 movl $SYS_futex, %eax
197 orl $FUTEX_WAITERS, %edx
199 cmpxchgl %edx, (%ebx)
203 cfi_adjust_cfa_offset(-12)
205 cfi_adjust_cfa_offset(-4)
208 cfi_adjust_cfa_offset(-4)
211 cfi_adjust_cfa_offset(-4)
214 cfi_adjust_cfa_offset(-4)
218 3: movl $EINVAL, %eax
221 cfi_adjust_cfa_offset(28)
223 cfi_offset(%esi, -12)
224 cfi_offset(%ebx, -16)
225 cfi_offset(%ebp, -20)
226 /* Check whether the time expired. */
227 7: cmpl $-ETIMEDOUT, %ecx
230 8: movl $ETIMEDOUT, %eax
233 .size __lll_robust_timedlock_wait,.-__lll_robust_timedlock_wait