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, 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>
29 .globl __pthread_rwlock_rdlock
30 .type __pthread_rwlock_rdlock,@function
31 .protected __pthread_rwlock_rdlock
33 __pthread_rwlock_rdlock:
44 cmpxchgl %esi, MUTEX(%rdi)
48 2: movl WRITER(%rdi), %eax
51 cmpl $0, WRITERS_QUEUED(%rdi)
56 3: incl READERS_QUEUED(%rdi)
59 movl READERS_WAKEUP(%rdi), %edx
70 #ifdef __ASSUME_PRIVATE_FUTEX
71 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %esi
72 xorl PSHARED(%rdi), %esi
75 movl PSHARED(%rdi), %esi
77 movl $FUTEX_WAIT, %esi
78 orl PSHARED(%rdi), %esi
80 xorl %fs:PRIVATE_FUTEX, %esi
82 addq $READERS_WAKEUP, %rdi
86 subq $READERS_WAKEUP, %rdi
95 cmpxchgl %esi, MUTEX(%rdi)
99 13: decl READERS_QUEUED(%rdi)
103 incl NR_READERS(%rdi)
117 1: movl PSHARED(%rdi), %esi
121 callq __lll_lock_wait
127 14: cmpl %fs:TID, %eax
129 /* Deadlock detected. */
133 6: movl PSHARED(%rdi), %esi
137 callq __lll_unlock_wake
144 8: decl NR_READERS(%rdi)
149 4: decl READERS_QUEUED(%rdi)
153 10: movl PSHARED(%rdi), %esi
157 callq __lll_unlock_wake
163 12: movl PSHARED(%rdi), %esi
167 callq __lll_lock_wait
173 .size __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock
175 .globl pthread_rwlock_rdlock
176 pthread_rwlock_rdlock = __pthread_rwlock_rdlock
178 .globl __pthread_rwlock_rdlock_internal
179 __pthread_rwlock_rdlock_internal = __pthread_rwlock_rdlock