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, see
17 <http://www.gnu.org/licenses/>. */
20 #include <pthread-errnos.h>
21 #include <lowlevellock.h>
22 #include <lowlevelrobustlock.h>
23 #include <kernel-features.h>
27 #define FUTEX_WAITERS 0x80000000
28 #define FUTEX_OWNER_DIED 0x40000000
30 #ifdef __ASSUME_PRIVATE_FUTEX
31 # define LOAD_FUTEX_WAIT(reg) \
32 xorl $(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
35 # define LOAD_FUTEX_WAIT(reg) \
36 xorl $FUTEX_PRIVATE_FLAG, reg ; \
37 andl %gs:PRIVATE_FUTEX, reg
39 # define LOAD_FUTEX_WAIT(reg) \
40 xorl $FUTEX_PRIVATE_FLAG, reg ; \
41 andl %gs:PRIVATE_FUTEX, reg ; \
46 .globl __lll_robust_lock_wait
47 .type __lll_robust_lock_wait,@function
48 .hidden __lll_robust_lock_wait
50 __lll_robust_lock_wait:
53 cfi_adjust_cfa_offset(4)
55 cfi_adjust_cfa_offset(4)
57 cfi_adjust_cfa_offset(4)
63 xorl %esi, %esi /* No timeout. */
64 LOAD_FUTEX_WAIT (%ecx)
67 orl $FUTEX_WAITERS, %edx
69 testl $FUTEX_OWNER_DIED, %eax
72 cmpl %edx, %eax /* NB: %edx == 2 */
79 1: movl $SYS_futex, %eax
88 orl $FUTEX_WAITERS, %edx
95 cfi_adjust_cfa_offset(-4)
98 cfi_adjust_cfa_offset(-4)
101 cfi_adjust_cfa_offset(-4)
105 .size __lll_robust_lock_wait,.-__lll_robust_lock_wait
108 .globl __lll_robust_timedlock_wait
109 .type __lll_robust_timedlock_wait,@function
110 .hidden __lll_robust_timedlock_wait
112 __lll_robust_timedlock_wait:
114 /* Check for a valid timeout value. */
115 cmpl $1000000000, 4(%edx)
119 cfi_adjust_cfa_offset(4)
121 cfi_adjust_cfa_offset(4)
123 cfi_adjust_cfa_offset(4)
125 cfi_adjust_cfa_offset(4)
127 cfi_offset(%esi, -12)
128 cfi_offset(%ebx, -16)
129 cfi_offset(%ebp, -20)
131 /* Stack frame for the timespec and timeval structs. */
133 cfi_adjust_cfa_offset(12)
138 1: movl %eax, 8(%esp)
140 /* Get current time. */
143 movl $__NR_gettimeofday, %eax
146 /* Compute relative timeout. */
149 mul %edx /* Milli seconds to nano seconds. */
155 addl $1000000000, %edx
158 js 8f /* Time is already up. */
160 /* Store relative timeout. */
168 orl $FUTEX_WAITERS, %edx
170 testl $FUTEX_OWNER_DIED, %eax
177 cmpxchgl %edx, (%ebx)
178 movl $0, %ecx /* Must use mov to avoid changing cc. */
185 LOAD_FUTEX_WAIT (%ecx)
186 movl $SYS_futex, %eax
196 orl $FUTEX_WAITERS, %edx
198 cmpxchgl %edx, (%ebx)
202 cfi_adjust_cfa_offset(-12)
204 cfi_adjust_cfa_offset(-4)
207 cfi_adjust_cfa_offset(-4)
210 cfi_adjust_cfa_offset(-4)
213 cfi_adjust_cfa_offset(-4)
217 3: movl $EINVAL, %eax
220 cfi_adjust_cfa_offset(28)
222 cfi_offset(%esi, -12)
223 cfi_offset(%ebx, -16)
224 cfi_offset(%ebp, -20)
225 /* Check whether the time expired. */
226 7: cmpl $-ETIMEDOUT, %ecx
229 8: movl $ETIMEDOUT, %eax
232 .size __lll_robust_timedlock_wait,.-__lll_robust_timedlock_wait