1 /* Copyright (C) 2002 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
30 #define SYS_gettimeofday __NR_gettimeofday
35 #define EWOULDBLOCK 11
40 #define cond_nr_wakers 4
41 #define cond_nr_sleepers 8
44 .global __lll_cond_wait
45 .type __lll_cond_wait,@function
46 .hidden __lll_cond_wait
54 leal cond_nr_wakers(%eax), %ebx
61 decl cond_lock-cond_nr_wakers(%ebx)
70 xaddl %eax, cond_lock-cond_nr_wakers(%ebx)
74 leal cond_lock-cond_nr_wakers(%ebx), %ecx
75 /* Preserves %ebx, %edx, %edi, %esi. */
76 call __lll_mutex_lock_wait
85 2: leal cond_lock-cond_nr_wakers(%ebx), %eax
86 /* Preserves %ebx, %ecx, %edx, %edi, %esi. */
87 call __lll_mutex_unlock_wake
89 .size __lll_cond_wait,.-__lll_cond_wait
92 .global __lll_cond_timedwait
93 .type __lll_cond_timedwait,@function
94 .hidden __lll_cond_timedwait
97 /* Check for a valid timeout value. */
98 cmpl $1000000000, 4(%edx)
106 /* Stack frame for the timespec and timeval structs. */
109 leal cond_nr_wakers(%eax), %ebp /* cond */
110 movl %edx, %edi /* timeout */
117 decl cond_lock-cond_nr_wakers(%ebp)
120 /* Get current time. */
123 movl $SYS_gettimeofday, %eax
126 /* Compute relative timeout. */
129 mul %edx /* Milli seconds to nano seconds. */
135 addl $1000000000, %edx
138 js 4f /* Time is already up. */
140 movl %ecx, (%esp) /* Store relative timeout. */
144 xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
146 movl $SYS_futex, %eax
153 xaddl %eax, cond_lock-cond_nr_wakers(%ebp)
157 cmpl $-ETIMEDOUT, %edx
160 4: movl $ETIMEDOUT, %eax
173 6: leal cond_lock-cond_nr_wakers(%ebp), %eax
174 /* Preserves %ebx, %ecx, %edx, %edi, %esi. */
175 call __lll_mutex_unlock_wake
178 8: leal cond_lock-cond_nr_wakers(%ebp), %ecx
179 /* Preserves %ebx, %edx, %edi, %esi. */
180 call __lll_mutex_lock_wait
183 1: movl $EINVAL, %eax
185 .size __lll_cond_timedwait,.-__lll_cond_timedwait
188 .global __lll_cond_wake
189 .type __lll_cond_wake,@function
190 .hidden __lll_cond_wake
204 2: leal cond_nr_wakers(%ebx), %ebx
205 cmpl $0, cond_nr_sleepers-cond_nr_wakers(%ebx)
211 6: movl $FUTEX_WAKE, %ecx
213 movl %ecx, %edx /* movl $1, %edx */
214 movl $SYS_futex, %eax
218 decl cond_lock-cond_nr_wakers(%ebx)
221 leal cond_lock-cond_nr_wakers(%ebx), %eax
222 call __lll_mutex_unlock_wake
229 call __lll_mutex_lock_wait
232 5: movl $0x80000000, (%ebx)
234 .size __lll_cond_wake,.-__lll_cond_wake
237 .global __lll_cond_broadcast
238 .type __lll_cond_broadcast,@function
239 .hidden __lll_cond_broadcast
241 __lll_cond_broadcast:
246 movl $0x8000000, %edx
254 2: leal cond_nr_wakers(%ebx), %ebx
255 cmpl $0, cond_nr_sleepers-cond_nr_wakers(%ebx)
260 6: movl $FUTEX_WAKE, %ecx
262 movl $SYS_futex, %eax
266 decl cond_lock-cond_nr_wakers(%ebx)
269 leal cond_lock-cond_nr_wakers(%ebx), %eax
270 call __lll_mutex_unlock_wake
277 call __lll_mutex_lock_wait
279 .size __lll_cond_broadcast,.-__lll_cond_broadcast