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 <kernel-features.h>
28 .globl __pthread_rwlock_rdlock
29 .type __pthread_rwlock_rdlock,@function
31 __pthread_rwlock_rdlock:
42 cmpxchgl %esi, MUTEX(%rdi)
46 2: movl WRITER(%rdi), %eax
49 cmpl $0, WRITERS_QUEUED(%rdi)
54 3: incl READERS_QUEUED(%rdi)
57 movl READERS_WAKEUP(%rdi), %edx
68 #ifdef __ASSUME_PRIVATE_FUTEX
69 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %esi
70 xorl PSHARED(%rdi), %esi
73 movl PSHARED(%rdi), %esi
75 movl $FUTEX_WAIT, %esi
76 orl PSHARED(%rdi), %esi
78 xorl %fs:PRIVATE_FUTEX, %esi
80 addq $READERS_WAKEUP, %rdi
84 subq $READERS_WAKEUP, %rdi
93 cmpxchgl %esi, MUTEX(%rdi)
97 13: decl READERS_QUEUED(%rdi)
101 incl NR_READERS(%rdi)
115 1: movl PSHARED(%rdi), %esi
119 callq __lll_lock_wait
125 14: cmpl %fs:TID, %eax
127 /* Deadlock detected. */
131 6: movl PSHARED(%rdi), %esi
135 callq __lll_unlock_wake
142 8: decl NR_READERS(%rdi)
147 4: decl READERS_QUEUED(%rdi)
151 10: movl PSHARED(%rdi), %esi
155 callq __lll_unlock_wake
161 12: movl PSHARED(%rdi), %esi
165 callq __lll_lock_wait
171 .size __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock
173 .globl pthread_rwlock_rdlock
174 pthread_rwlock_rdlock = __pthread_rwlock_rdlock
176 .globl __pthread_rwlock_rdlock_internal
177 __pthread_rwlock_rdlock_internal = __pthread_rwlock_rdlock