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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <lowlevellock.h>
22 #include <lowlevelrwlock.h>
23 #include <pthread-errnos.h>
24 #include <bits/kernel-features.h>
30 .globl pthread_rwlock_timedwrlock
31 .type pthread_rwlock_timedwrlock,@function
33 pthread_rwlock_timedwrlock:
36 cfi_adjust_cfa_offset(4)
38 cfi_adjust_cfa_offset(4)
40 cfi_adjust_cfa_offset(4)
42 cfi_adjust_cfa_offset(4)
48 cfi_adjust_cfa_offset(8)
60 cmpxchgl %edx, MUTEX(%ebp)
64 2: movl WRITER(%ebp), %eax
67 cmpl $0, NR_READERS(%ebp)
70 /* Check the value of the timeout parameter. */
71 3: cmpl $1000000000, 4(%edi)
74 addl $1, WRITERS_QUEUED(%ebp)
77 movl WRITERS_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 WRITERS_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, WRITERS_QUEUED(%ebp)
141 cmpl $-ETIMEDOUT, %esi
144 18: movl $ETIMEDOUT, %edx
150 movl %eax, WRITER(%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
194 20: movl $EDEADLK, %edx
201 leal MUTEX(%ebp), %eax
203 movzbl PSHARED(%ebp), %ecx
204 call __lll_unlock_wake
208 4: subl $1, WRITERS_QUEUED(%ebp)
216 leal MUTEX(%ebp), %eax
218 movzbl PSHARED(%ebp), %ecx
219 call __lll_unlock_wake
226 leal MUTEX(%ebp), %edx
228 movzbl PSHARED(%ebp), %ecx
232 16: movl $-ETIMEDOUT, %esi
235 19: movl $EINVAL, %edx
238 .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock