1 /* Copyright (C) 2002-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, see
17 <http://www.gnu.org/licenses/>. */
20 #include <lowlevellock.h>
21 #include <lowlevelrwlock.h>
22 #include <pthread-errnos.h>
23 #include <bits/kernel-features.h>
24 #include <tcb-offsets.h>
27 /* For the calculation see asm/vsyscall.h. */
28 #define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
32 .globl pthread_rwlock_timedrdlock
33 .type pthread_rwlock_timedrdlock,@function
35 pthread_rwlock_timedrdlock:
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, WRITERS_QUEUED(%r12)
77 /* Check the value of the timeout parameter. */
78 3: cmpq $1000000000, 8(%r13)
81 incl READERS_QUEUED(%r12)
84 movl READERS_WAKEUP(%r12), VALREG
96 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
98 cmpl $0, __have_futex_clock_realtime@GOTOFF(%rip)
100 cmpl $0, __have_futex_clock_realtime
105 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, %esi
106 xorl PSHARED(%r12), %esi
108 movl $0xffffffff, %r9d
109 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
112 21: leaq READERS_WAKEUP(%r12), %rdi
113 movl $SYS_futex, %eax
117 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
120 /* Get current time. */
123 movq $VSYSCALL_ADDR_vgettimeofday, %rax
126 /* Compute relative timeout. */
129 mul %rdi /* Milli seconds to nano seconds. */
135 addq $1000000000, %rdi
138 js 16f /* Time is already up. */
141 movq %rcx, (%rsp) /* Store relative timeout. */
144 # ifdef __ASSUME_PRIVATE_FUTEX
145 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %esi
146 xorl PSHARED(%r12), %esi
149 movl PSHARED(%r12), %esi
151 movl $FUTEX_WAIT, %esi
152 orl PSHARED(%r12), %esi
154 xorl %fs:PRIVATE_FUTEX, %esi
163 17: /* Reget the lock. */
168 cmpxchgl %esi, (%r12)
170 cmpxchgl %esi, MUTEX(%r12)
174 13: decl READERS_QUEUED(%r12)
175 cmpq $-ETIMEDOUT, %rdx
178 18: movl $ETIMEDOUT, %edx
183 incl NR_READERS(%r12)
195 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
197 cfi_adjust_cfa_offset(-16)
199 cfi_adjust_cfa_offset(-8)
203 cfi_adjust_cfa_offset(-8)
206 cfi_adjust_cfa_offset(-8)
210 #ifdef __ASSUME_PRIVATE_FUTEX
211 cfi_adjust_cfa_offset(16)
212 cfi_rel_offset(%r12, 8)
213 cfi_rel_offset(%r13, 0)
215 cfi_adjust_cfa_offset(40)
216 cfi_offset(%r12, -16)
217 cfi_offset(%r13, -24)
218 cfi_offset(%r14, -32)
220 1: movl PSHARED(%rdi), %esi
224 callq __lll_lock_wait
227 14: cmpl %fs:TID, %eax
232 6: movl PSHARED(%r12), %esi
236 leal MUTEX(%r12), %rdi
238 callq __lll_unlock_wake
242 8: decl NR_READERS(%r12)
247 4: decl READERS_QUEUED(%r12)
251 10: movl PSHARED(%r12), %esi
255 leaq MUTEX(%r12), %rdi
257 callq __lll_unlock_wake
260 12: movl PSHARED(%r12), %esi
264 leaq MUTEX(%r12), %rdi
266 callq __lll_lock_wait
269 16: movq $-ETIMEDOUT, %rdx
272 19: movl $EINVAL, %edx
275 .size pthread_rwlock_timedrdlock,.-pthread_rwlock_timedrdlock