1 /* Copyright (C) 2002, 2003 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>
29 /* For the calculation see asm/vsyscall.h. */
30 #define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
41 .globl pthread_rwlock_timedwrlock
42 .type pthread_rwlock_timedwrlock,@function
44 pthread_rwlock_timedwrlock:
60 cmpxchgl %esi, MUTEX(%rdi)
64 2: movl WRITER(%r12), %eax
67 cmpl $0, NR_READERS(%r12)
70 /* Check the value of the timeout parameter. */
71 3: cmpq $1000000000, 8(%r13)
74 incl WRITERS_QUEUED(%r12)
77 movl WRITERS_WAKEUP(%r12), %r14d
87 /* Get current time. */
90 movq $VSYSCALL_ADDR_vgettimeofday, %rax
93 /* Compute relative timeout. */
96 mul %rdi /* Milli seconds to nano seconds. */
102 addq $1000000000, %rdi
105 js 16f /* Time is already up. */
108 movq %rcx, (%rsp) /* Store relative timeout. */
111 xorq %rsi, %rsi /* movq $FUTEX_WAIT, %rsi */
114 leaq WRITERS_WAKEUP(%r12), %rdi
115 movq $SYS_futex, %rax
120 /* Reget the lock. */
125 cmpxchgl %esi, (%r12)
127 cmpxchgl %esi, MUTEX(%r12)
131 13: decl WRITERS_QUEUED(%r12)
132 cmpq $-ETIMEDOUT, %rdx
135 18: movq $ETIMEDOUT, %rdx
141 movl %eax, WRITER(%r12)
162 callq __lll_mutex_lock_wait
165 14: cmpl %fs:TID, %eax
167 20: movq $EDEADLK, %rdx
174 leal MUTEX(%r12), %rdi
176 callq __lll_mutex_unlock_wake
180 4: decl WRITERS_QUEUED(%r12)
188 leaq MUTEX(%r12), %rdi
190 callq __lll_mutex_unlock_wake
197 leaq MUTEX(%r12), %rdi
199 callq __lll_mutex_lock_wait
202 16: movq $-ETIMEDOUT, %rdx
205 19: movq $EINVAL, %rdx
207 .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock