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 <bits/kernel-features.h>
29 #define FUTEX_WAITERS 0x80000000
30 #define FUTEX_OWNER_DIED 0x40000000
32 #ifdef __ASSUME_PRIVATE_FUTEX
33 # define LOAD_FUTEX_WAIT(reg) \
34 xorl $(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
37 # define LOAD_FUTEX_WAIT(reg) \
38 xorl $FUTEX_PRIVATE_FLAG, reg ; \
39 andl %gs:PRIVATE_FUTEX, reg
41 # define LOAD_FUTEX_WAIT(reg) \
42 xorl $FUTEX_PRIVATE_FLAG, reg ; \
43 andl %gs:PRIVATE_FUTEX, reg ; \
48 .globl __lll_robust_lock_wait
49 .type __lll_robust_lock_wait,@function
50 .hidden __lll_robust_lock_wait
52 __lll_robust_lock_wait:
55 cfi_adjust_cfa_offset(4)
57 cfi_adjust_cfa_offset(4)
59 cfi_adjust_cfa_offset(4)
65 xorl %esi, %esi /* No timeout. */
66 LOAD_FUTEX_WAIT (%ecx)
69 orl $FUTEX_WAITERS, %edx
71 testl $FUTEX_OWNER_DIED, %eax
74 cmpl %edx, %eax /* NB: %edx == 2 */
81 1: movl $SYS_futex, %eax
90 orl $FUTEX_WAITERS, %edx
97 cfi_adjust_cfa_offset(-4)
100 cfi_adjust_cfa_offset(-4)
103 cfi_adjust_cfa_offset(-4)
107 .size __lll_robust_lock_wait,.-__lll_robust_lock_wait
110 .globl __lll_robust_timedlock_wait
111 .type __lll_robust_timedlock_wait,@function
112 .hidden __lll_robust_timedlock_wait
114 __lll_robust_timedlock_wait:
116 /* Check for a valid timeout value. */
117 cmpl $1000000000, 4(%edx)
121 cfi_adjust_cfa_offset(4)
123 cfi_adjust_cfa_offset(4)
125 cfi_adjust_cfa_offset(4)
127 cfi_adjust_cfa_offset(4)
129 cfi_offset(%esi, -12)
130 cfi_offset(%ebx, -16)
131 cfi_offset(%ebp, -20)
133 /* Stack frame for the timespec and timeval structs. */
135 cfi_adjust_cfa_offset(12)
140 1: movl %eax, 8(%esp)
142 /* Get current time. */
145 movl $__NR_gettimeofday, %eax
148 /* Compute relative timeout. */
151 mul %edx /* Milli seconds to nano seconds. */
157 addl $1000000000, %edx
160 js 8f /* Time is already up. */
162 /* Store relative timeout. */
170 orl $FUTEX_WAITERS, %edx
172 testl $FUTEX_OWNER_DIED, %eax
179 cmpxchgl %edx, (%ebx)
180 movl $0, %ecx /* Must use mov to avoid changing cc. */
187 LOAD_FUTEX_WAIT (%ecx)
188 movl $SYS_futex, %eax
198 orl $FUTEX_WAITERS, %edx
200 cmpxchgl %edx, (%ebx)
204 cfi_adjust_cfa_offset(-12)
206 cfi_adjust_cfa_offset(-4)
209 cfi_adjust_cfa_offset(-4)
212 cfi_adjust_cfa_offset(-4)
215 cfi_adjust_cfa_offset(-4)
219 3: movl $EINVAL, %eax
222 cfi_adjust_cfa_offset(28)
224 cfi_offset(%esi, -12)
225 cfi_offset(%ebx, -16)
226 cfi_offset(%ebp, -20)
227 /* Check whether the time expired. */
228 7: cmpl $-ETIMEDOUT, %ecx
231 8: movl $ETIMEDOUT, %eax
234 .size __lll_robust_timedlock_wait,.-__lll_robust_timedlock_wait