1 /* Copyright (C) 2002, 2003, 2005, 2007, 2009 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 <kernel-features.h>
27 /* For the calculation see asm/vsyscall.h. */
28 #define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
32 .globl pthread_rwlock_timedwrlock
33 .type pthread_rwlock_timedwrlock,@function
35 pthread_rwlock_timedwrlock:
38 cfi_adjust_cfa_offset(8)
39 cfi_rel_offset(%r12, 0)
41 cfi_adjust_cfa_offset(8)
42 cfi_rel_offset(%r13, 0)
43 #ifdef __ASSUME_FUTEX_CLOCK_REALTIME
47 cfi_adjust_cfa_offset(8)
48 cfi_rel_offset(%r14, 0)
51 cfi_adjust_cfa_offset(16)
65 cmpxchgl %esi, MUTEX(%rdi)
69 2: movl WRITER(%r12), %eax
72 cmpl $0, NR_READERS(%r12)
75 /* Check the value of the timeout parameter. */
76 3: cmpq $1000000000, 8(%r13)
79 incl WRITERS_QUEUED(%r12)
82 movl WRITERS_WAKEUP(%r12), VALREG
93 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
95 cmpl $0, __have_futex_clock_realtime(%rip)
97 cmpl $0, __have_futex_clock_realtime
102 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, %esi
103 xorl PSHARED(%r12), %esi
105 movl $0xffffffff, %r9d
106 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
109 21: leaq WRITERS_WAKEUP(%r12), %rdi
110 movl $SYS_futex, %eax
114 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
117 /* Get current time. */
120 movq $VSYSCALL_ADDR_vgettimeofday, %rax
123 /* Compute relative timeout. */
126 mul %rdi /* Milli seconds to nano seconds. */
132 addq $1000000000, %rdi
135 js 16f /* Time is already up. */
138 movq %rcx, (%rsp) /* Store relative timeout. */
141 #ifdef __ASSUME_PRIVATE_FUTEX
142 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %esi
143 xorl PSHARED(%r12), %esi
146 movl PSHARED(%r12), %esi
148 movl $FUTEX_WAIT, %esi
149 orl PSHARED(%r12), %esi
151 xorl %fs:PRIVATE_FUTEX, %esi
160 17: /* Reget the lock. */
165 cmpxchgl %esi, (%r12)
167 cmpxchgl %esi, MUTEX(%r12)
171 13: decl WRITERS_QUEUED(%r12)
172 cmpq $-ETIMEDOUT, %rdx
175 18: movl $ETIMEDOUT, %edx
181 movl %eax, WRITER(%r12)
192 #ifndef __ASSUME_PRIVATE_FUTEX
194 cfi_adjust_cfa_offset(-16)
196 cfi_adjust_cfa_offset(-8)
200 cfi_adjust_cfa_offset(-8)
203 cfi_adjust_cfa_offset(-8)
207 #ifdef __ASSUME_PRIVATE_FUTEX
208 cfi_adjust_cfa_offset(16)
209 cfi_rel_offset(%r12, 8)
210 cfi_rel_offset(%r13, 0)
212 cfi_adjust_cfa_offset(40)
213 cfi_offset(%r12, -16)
214 cfi_offset(%r13, -24)
215 cfi_offset(%r14, -32)
217 1: movl PSHARED(%rdi), %esi
221 callq __lll_lock_wait
224 14: cmpl %fs:TID, %eax
226 20: movl $EDEADLK, %edx
229 6: movl PSHARED(%r12), %esi
233 leal MUTEX(%r12), %rdi
235 callq __lll_unlock_wake
239 4: decl WRITERS_QUEUED(%r12)
243 10: movl PSHARED(%r12), %esi
247 leaq MUTEX(%r12), %rdi
249 callq __lll_unlock_wake
252 12: movl PSHARED(%r12), %esi
256 leaq MUTEX(%r12), %rdi
258 callq __lll_lock_wait
261 16: movq $-ETIMEDOUT, %rdx
264 19: movl $EINVAL, %edx
267 .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock