1 /* Copyright (C) 2002-2012 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>
24 #include <stap-probe.h>
28 .globl __pthread_rwlock_rdlock
29 .type __pthread_rwlock_rdlock,@function
31 __pthread_rwlock_rdlock:
34 LIBC_PROBE (rdlock_entry, 1, %rdi)
45 cmpxchgl %esi, MUTEX(%rdi)
49 2: movl WRITER(%rdi), %eax
52 cmpl $0, WRITERS_QUEUED(%rdi)
57 3: incl READERS_QUEUED(%rdi)
60 movl READERS_WAKEUP(%rdi), %edx
71 #ifdef __ASSUME_PRIVATE_FUTEX
72 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %esi
73 xorl PSHARED(%rdi), %esi
76 movl PSHARED(%rdi), %esi
78 movl $FUTEX_WAIT, %esi
79 orl PSHARED(%rdi), %esi
81 xorl %fs:PRIVATE_FUTEX, %esi
83 addq $READERS_WAKEUP, %rdi
87 subq $READERS_WAKEUP, %rdi
96 cmpxchgl %esi, MUTEX(%rdi)
100 13: decl READERS_QUEUED(%rdi)
104 incl NR_READERS(%rdi)
118 1: movl PSHARED(%rdi), %esi
122 callq __lll_lock_wait
128 14: cmpl %fs:TID, %eax
130 /* Deadlock detected. */
134 6: movl PSHARED(%rdi), %esi
138 callq __lll_unlock_wake
145 8: decl NR_READERS(%rdi)
150 4: decl READERS_QUEUED(%rdi)
154 10: movl PSHARED(%rdi), %esi
158 callq __lll_unlock_wake
164 12: movl PSHARED(%rdi), %esi
168 callq __lll_lock_wait
174 .size __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock
176 strong_alias (__pthread_rwlock_rdlock, pthread_rwlock_rdlock)
177 hidden_def (__pthread_rwlock_rdlock)