1 /* Copyright (C) 2002, 2003, 2004, 2005, 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 <kernel-features.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)
40 cfi_adjust_cfa_offset(8)
42 cfi_adjust_cfa_offset(8)
48 cfi_adjust_cfa_offset(16)
60 cmpxchgl %esi, MUTEX(%rdi)
64 2: movl WRITER(%r12), %eax
67 cmpl $0, WRITERS_QUEUED(%r12)
72 /* Check the value of the timeout parameter. */
73 3: cmpq $1000000000, 8(%r13)
76 incl READERS_QUEUED(%r12)
79 movl READERS_WAKEUP(%r12), %r14d
90 /* Get current time. */
93 movq $VSYSCALL_ADDR_vgettimeofday, %rax
96 /* Compute relative timeout. */
99 mul %rdi /* Milli seconds to nano seconds. */
105 addq $1000000000, %rdi
108 js 16f /* Time is already up. */
111 movq %rcx, (%rsp) /* Store relative timeout. */
114 #ifdef __ASSUME_PRIVATE_FUTEX
115 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %esi
116 xorl PSHARED(%r12), %esi
119 movl PSHARED(%r12), %esi
121 movl $FUTEX_WAIT, %esi
122 orl PSHARED(%r12), %esi
124 xorl %fs:PRIVATE_FUTEX, %esi
128 leaq READERS_WAKEUP(%r12), %rdi
129 movl $SYS_futex, %eax
134 /* Reget the lock. */
139 cmpxchgl %esi, (%r12)
141 cmpxchgl %esi, MUTEX(%r12)
145 13: decl READERS_QUEUED(%r12)
146 cmpq $-ETIMEDOUT, %rdx
149 18: movl $ETIMEDOUT, %edx
154 incl NR_READERS(%r12)
167 cfi_adjust_cfa_offset(-16)
169 cfi_adjust_cfa_offset(-8)
172 cfi_adjust_cfa_offset(-8)
175 cfi_adjust_cfa_offset(-8)
179 cfi_adjust_cfa_offset(40)
180 cfi_offset(%r12, -16)
181 cfi_offset(%r13, -24)
182 cfi_offset(%r14, -32)
183 1: movl PSHARED(%rdi), %esi
187 callq __lll_lock_wait
190 14: cmpl %fs:TID, %eax
195 6: movl PSHARED(%r12), %esi
199 leal MUTEX(%r12), %rdi
201 callq __lll_unlock_wake
205 8: decl NR_READERS(%r12)
210 4: decl READERS_QUEUED(%r12)
214 10: movl PSHARED(%r12), %esi
218 leaq MUTEX(%r12), %rdi
220 callq __lll_unlock_wake
223 12: movl PSHARED(%r12), %esi
227 leaq MUTEX(%r12), %rdi
229 callq __lll_lock_wait
232 16: movq $-ETIMEDOUT, %rdx
235 19: movl $EINVAL, %edx
238 .size pthread_rwlock_timedrdlock,.-pthread_rwlock_timedrdlock