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>
33 #define SYS_gettimeofday __NR_gettimeofday
39 .globl __lll_mutex_lock_wait
40 .type __lll_mutex_lock_wait,@function
41 .hidden __lll_mutex_lock_wait
43 __lll_mutex_lock_wait:
46 cfi_adjust_cfa_offset(4)
48 cfi_adjust_cfa_offset(4)
50 cfi_adjust_cfa_offset(4)
57 xorl %esi, %esi /* No timeout. */
58 xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
60 cmpl %edx, %eax /* NB: %edx == 2 */
63 1: movl $SYS_futex, %eax
67 xchgl %eax, (%ebx) /* NB: lock is implied */
73 cfi_adjust_cfa_offset(-4)
76 cfi_adjust_cfa_offset(-4)
79 cfi_adjust_cfa_offset(-4)
83 .size __lll_mutex_lock_wait,.-__lll_mutex_lock_wait
87 .globl __lll_mutex_timedlock_wait
88 .type __lll_mutex_timedlock_wait,@function
89 .hidden __lll_mutex_timedlock_wait
91 __lll_mutex_timedlock_wait:
93 /* Check for a valid timeout value. */
94 cmpl $1000000000, 4(%edx)
98 cfi_adjust_cfa_offset(4)
100 cfi_adjust_cfa_offset(4)
102 cfi_adjust_cfa_offset(4)
104 cfi_adjust_cfa_offset(4)
106 cfi_offset(%esi, -12)
107 cfi_offset(%ebx, -16)
108 cfi_offset(%ebp, -20)
110 /* Stack frame for the timespec and timeval structs. */
112 cfi_adjust_cfa_offset(8)
118 /* Get current time. */
121 movl $SYS_gettimeofday, %eax
124 /* Compute relative timeout. */
127 mul %edx /* Milli seconds to nano seconds. */
133 addl $1000000000, %edx
136 js 5f /* Time is already up. */
138 /* Store relative timeout. */
147 cmpxchgl %edx, (%ebx)
154 xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
155 movl $SYS_futex, %eax
159 8: /* NB: %edx == 2 */
162 cmpxchgl %edx, (%ebx)
167 cfi_adjust_cfa_offset(-8)
169 cfi_adjust_cfa_offset(-4)
172 cfi_adjust_cfa_offset(-4)
175 cfi_adjust_cfa_offset(-4)
178 cfi_adjust_cfa_offset(-4)
182 3: movl $EINVAL, %eax
185 cfi_adjust_cfa_offset(24)
187 cfi_offset(%esi, -12)
188 cfi_offset(%ebx, -16)
189 cfi_offset(%ebp, -20)
190 /* Check whether the time expired. */
191 7: cmpl $-ETIMEDOUT, %ecx
194 /* Make sure the current holder knows we are going to sleep. */
201 5: movl $ETIMEDOUT, %eax
204 .size __lll_mutex_timedlock_wait,.-__lll_mutex_timedlock_wait
209 .globl lll_unlock_wake_cb
210 .type lll_unlock_wake_cb,@function
211 .hidden lll_unlock_wake_cb
223 movl $FUTEX_WAKE, %ecx
224 movl $1, %edx /* Wake one thread. */
225 movl $SYS_futex, %eax
233 .size lll_unlock_wake_cb,.-lll_unlock_wake_cb
237 .globl __lll_mutex_unlock_wake
238 .type __lll_mutex_unlock_wake,@function
239 .hidden __lll_mutex_unlock_wake
241 __lll_mutex_unlock_wake:
244 cfi_adjust_cfa_offset(4)
246 cfi_adjust_cfa_offset(4)
248 cfi_adjust_cfa_offset(4)
250 cfi_offset(%ecx, -12)
251 cfi_offset(%edx, -16)
255 movl $FUTEX_WAKE, %ecx
256 movl $1, %edx /* Wake one thread. */
257 movl $SYS_futex, %eax
261 cfi_adjust_cfa_offset(-4)
264 cfi_adjust_cfa_offset(-4)
267 cfi_adjust_cfa_offset(-4)
271 .size __lll_mutex_unlock_wake,.-__lll_mutex_unlock_wake
275 .globl __lll_timedwait_tid
276 .type __lll_timedwait_tid,@function
277 .hidden __lll_timedwait_tid
289 /* Get current time. */
292 movl $SYS_gettimeofday, %eax
295 /* Compute relative timeout. */
298 mul %edx /* Milli seconds to nano seconds. */
304 addl $1000000000, %edx
307 js 6f /* Time is already up. */
309 movl %ecx, (%esp) /* Store relative timeout. */
317 xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
319 movl $SYS_futex, %eax
333 1: cmpl $-ETIMEDOUT, %eax
335 6: movl $ETIMEDOUT, %eax
337 .size __lll_timedwait_tid,.-__lll_timedwait_tid