1 /* Copyright (C) 2002, 2003, 2004 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:
50 xorl %esi, %esi /* No timeout. */
51 xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
53 cmpl %edx, %eax /* NB: %edx == 2 */
56 1: movl $SYS_futex, %eax
60 xchgl %eax, (%ebx) /* NB: lock is implied */
69 .size __lll_mutex_lock_wait,.-__lll_mutex_lock_wait
73 .globl __lll_mutex_timedlock_wait
74 .type __lll_mutex_timedlock_wait,@function
75 .hidden __lll_mutex_timedlock_wait
77 __lll_mutex_timedlock_wait:
78 /* Check for a valid timeout value. */
79 cmpl $1000000000, 4(%edx)
87 /* Stack frame for the timespec and timeval structs. */
94 /* Get current time. */
97 movl $SYS_gettimeofday, %eax
100 /* Compute relative timeout. */
103 mul %edx /* Milli seconds to nano seconds. */
109 addl $1000000000, %edx
112 js 5f /* Time is already up. */
114 /* Store relative timeout. */
123 cmpxchgl %edx, (%ebx)
130 xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
131 movl $SYS_futex, %eax
135 8: /* NB: %edx == 2 */
138 cmpxchgl %edx, (%ebx)
149 /* Check whether the time expired. */
150 7: cmpl $-ETIMEDOUT, %ecx
153 /* Make sure the current holder knows we are going to sleep. */
160 3: movl $EINVAL, %eax
163 5: movl $ETIMEDOUT, %eax
165 .size __lll_mutex_timedlock_wait,.-__lll_mutex_timedlock_wait
170 .globl lll_unlock_wake_cb
171 .type lll_unlock_wake_cb,@function
172 .hidden lll_unlock_wake_cb
184 movl $FUTEX_WAKE, %ecx
185 movl $1, %edx /* Wake one thread. */
186 movl $SYS_futex, %eax
194 .size lll_unlock_wake_cb,.-lll_unlock_wake_cb
198 .globl __lll_mutex_unlock_wake
199 .type __lll_mutex_unlock_wake,@function
200 .hidden __lll_mutex_unlock_wake
202 __lll_mutex_unlock_wake:
209 movl $FUTEX_WAKE, %ecx
210 movl $1, %edx /* Wake one thread. */
211 movl $SYS_futex, %eax
218 .size __lll_mutex_unlock_wake,.-__lll_mutex_unlock_wake
222 .globl __lll_timedwait_tid
223 .type __lll_timedwait_tid,@function
224 .hidden __lll_timedwait_tid
236 /* Get current time. */
239 movl $SYS_gettimeofday, %eax
242 /* Compute relative timeout. */
245 mul %edx /* Milli seconds to nano seconds. */
251 addl $1000000000, %edx
254 js 6f /* Time is already up. */
256 movl %ecx, (%esp) /* Store relative timeout. */
264 xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
266 movl $SYS_futex, %eax
280 1: cmpl $-ETIMEDOUT, %eax
282 6: movl $ETIMEDOUT, %eax
284 .size __lll_timedwait_tid,.-__lll_timedwait_tid