1 /* Copyright (C) 2002, 2003, 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 <lowlevellock.h>
21 #include <lowlevelrwlock.h>
22 #include <pthread-errnos.h>
23 #include <kernel-features.h>
28 .globl pthread_rwlock_timedrdlock
29 .type pthread_rwlock_timedrdlock,@function
31 pthread_rwlock_timedrdlock:
34 cfi_adjust_cfa_offset(4)
36 cfi_adjust_cfa_offset(4)
38 cfi_adjust_cfa_offset(4)
40 cfi_adjust_cfa_offset(4)
46 cfi_adjust_cfa_offset(8)
58 cmpxchgl %edx, MUTEX(%ebp)
62 2: movl WRITER(%ebp), %eax
65 cmpl $0, WRITERS_QUEUED(%ebp)
70 /* Check the value of the timeout parameter. */
71 3: cmpl $1000000000, 4(%edi)
74 addl $1, READERS_QUEUED(%ebp)
77 movl READERS_WAKEUP(%ebp), %esi
87 /* Get current time. */
90 movl $__NR_gettimeofday, %eax
93 /* Compute relative timeout. */
96 mul %edx /* Milli seconds to nano seconds. */
102 addl $1000000000, %edx
105 js 16f /* Time is already up. */
108 movl %ecx, (%esp) /* Store relative timeout. */
112 #ifdef __ASSUME_PRIVATE_FUTEX
113 movzbl PSHARED(%ebp), %ecx
114 xorl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %ecx
116 movzbl PSHARED(%ebp), %ecx
118 orl $FUTEX_WAIT, %ecx
120 xorl %gs:PRIVATE_FUTEX, %ecx
123 leal READERS_WAKEUP(%ebp), %ebx
124 movl $SYS_futex, %eax
129 /* Reget the lock. */
134 cmpxchgl %edx, (%ebp)
136 cmpxchgl %edx, MUTEX(%ebp)
140 13: subl $1, READERS_QUEUED(%ebp)
141 cmpl $-ETIMEDOUT, %esi
144 18: movl $ETIMEDOUT, %edx
149 addl $1, NR_READERS(%ebp)
162 cfi_adjust_cfa_offset(-8)
164 cfi_adjust_cfa_offset(-4)
167 cfi_adjust_cfa_offset(-4)
170 cfi_adjust_cfa_offset(-4)
173 cfi_adjust_cfa_offset(-4)
177 cfi_adjust_cfa_offset(24)
179 cfi_offset(%edi, -12)
180 cfi_offset(%ebx, -16)
181 cfi_offset(%ebp, -20)
186 leal MUTEX(%ebp), %edx
188 movzbl PSHARED(%ebp), %ecx
192 14: cmpl %gs:TID, %eax
201 leal MUTEX(%ebp), %eax
203 movzbl PSHARED(%ebp), %ecx
204 call __lll_unlock_wake
208 8: subl $1, NR_READERS(%ebp)
213 4: subl $1, READERS_QUEUED(%ebp)
221 leal MUTEX(%ebp), %eax
223 movzbl PSHARED(%ebp), %ecx
224 call __lll_unlock_wake
231 leal MUTEX(%ebp), %edx
233 movzbl PSHARED(%ebp), %ecx
237 16: movl $-ETIMEDOUT, %esi
240 19: movl $EINVAL, %edx
243 .size pthread_rwlock_timedrdlock,.-pthread_rwlock_timedrdlock