1 /* Copyright (C) 2002-2014 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_timedwrlock
29 .type pthread_rwlock_timedwrlock,@function
31 pthread_rwlock_timedwrlock:
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, NR_READERS(%ebp)
68 /* Check the value of the timeout parameter. */
69 3: cmpl $1000000000, 4(%edi)
72 addl $1, WRITERS_QUEUED(%ebp)
75 movl WRITERS_WAKEUP(%ebp), %esi
85 /* Get current time. */
88 movl $__NR_gettimeofday, %eax
91 /* Compute relative timeout. */
94 mul %edx /* Milli seconds to nano seconds. */
100 addl $1000000000, %edx
103 js 16f /* Time is already up. */
106 movl %ecx, (%esp) /* Store relative timeout. */
110 #ifdef __ASSUME_PRIVATE_FUTEX
111 movzbl PSHARED(%ebp), %ecx
112 xorl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %ecx
114 movzbl PSHARED(%ebp), %ecx
116 orl $FUTEX_WAIT, %ecx
118 xorl %gs:PRIVATE_FUTEX, %ecx
121 leal WRITERS_WAKEUP(%ebp), %ebx
122 movl $SYS_futex, %eax
127 /* Reget the lock. */
132 cmpxchgl %edx, (%ebp)
134 cmpxchgl %edx, MUTEX(%ebp)
138 13: subl $1, WRITERS_QUEUED(%ebp)
139 cmpl $-ETIMEDOUT, %esi
142 18: movl $ETIMEDOUT, %edx
148 movl %eax, WRITER(%ebp)
160 cfi_adjust_cfa_offset(-8)
162 cfi_adjust_cfa_offset(-4)
165 cfi_adjust_cfa_offset(-4)
168 cfi_adjust_cfa_offset(-4)
171 cfi_adjust_cfa_offset(-4)
175 cfi_adjust_cfa_offset(24)
177 cfi_offset(%edi, -12)
178 cfi_offset(%ebx, -16)
179 cfi_offset(%ebp, -20)
184 leal MUTEX(%ebp), %edx
186 movzbl PSHARED(%ebp), %ecx
190 14: cmpl %gs:TID, %eax
192 20: movl $EDEADLK, %edx
199 leal MUTEX(%ebp), %eax
201 movzbl PSHARED(%ebp), %ecx
202 call __lll_unlock_wake
206 4: subl $1, WRITERS_QUEUED(%ebp)
214 leal MUTEX(%ebp), %eax
216 movzbl PSHARED(%ebp), %ecx
217 call __lll_unlock_wake
224 leal MUTEX(%ebp), %edx
226 movzbl PSHARED(%ebp), %ecx
230 16: movl $-ETIMEDOUT, %esi
233 19: movl $EINVAL, %edx
236 .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock