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 <lowlevelrwlock.h>
22 #include <pthread-errnos.h>
23 #include <kernel-features.h>
29 #define FUTEX_PRIVATE_FLAG 128
31 /* For the calculation see asm/vsyscall.h. */
32 #define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
44 .globl pthread_rwlock_timedrdlock
45 .type pthread_rwlock_timedrdlock,@function
47 pthread_rwlock_timedrdlock:
63 cmpxchgl %esi, MUTEX(%rdi)
67 2: movl WRITER(%r12), %eax
70 cmpl $0, WRITERS_QUEUED(%r12)
75 /* Check the value of the timeout parameter. */
76 3: cmpq $1000000000, 8(%r13)
79 incl READERS_QUEUED(%r12)
82 movl READERS_WAKEUP(%r12), %r14d
93 /* Get current time. */
96 movq $VSYSCALL_ADDR_vgettimeofday, %rax
99 /* Compute relative timeout. */
102 mul %rdi /* Milli seconds to nano seconds. */
108 addq $1000000000, %rdi
111 js 16f /* Time is already up. */
114 movq %rcx, (%rsp) /* Store relative timeout. */
117 #ifdef __ASSUME_PRIVATE_FUTEX
118 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %esi
119 xorl PSHARED(%r12), %esi
122 movl PSHARED(%r12), %esi
124 movl $FUTEX_WAIT, %esi
125 orl PSHARED(%r12), %esi
127 xorl %fs:PRIVATE_FUTEX, %esi
131 leaq READERS_WAKEUP(%r12), %rdi
132 movl $SYS_futex, %eax
137 /* Reget the lock. */
142 cmpxchgl %esi, (%r12)
144 cmpxchgl %esi, MUTEX(%r12)
148 13: decl READERS_QUEUED(%r12)
149 cmpq $-ETIMEDOUT, %rdx
152 18: movl $ETIMEDOUT, %edx
157 incl NR_READERS(%r12)
179 callq __lll_mutex_lock_wait
182 14: cmpl %fs:TID, %eax
191 leal MUTEX(%r12), %rdi
193 callq __lll_mutex_unlock_wake
197 8: decl NR_READERS(%r12)
202 4: decl READERS_QUEUED(%r12)
210 leaq MUTEX(%r12), %rdi
212 callq __lll_mutex_unlock_wake
219 leaq MUTEX(%r12), %rdi
221 callq __lll_mutex_lock_wait
224 16: movq $-ETIMEDOUT, %rdx
227 19: movl $EINVAL, %edx
229 .size pthread_rwlock_timedrdlock,.-pthread_rwlock_timedrdlock