1 /* Copyright (C) 2003-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
19 #include <lowlevellock.h>
20 #include <lowlevelrwlock.h>
21 #include <pthread-errnos.h>
22 #include <tcb-offsets.h>
23 #include <kernel-features.h>
24 #include "lowlevel-atomic.h"
29 .globl __pthread_rwlock_rdlock
30 .type __pthread_rwlock_rdlock,@function
33 __pthread_rwlock_rdlock:
35 cfi_adjust_cfa_offset (4)
36 cfi_rel_offset (r12, 0)
38 cfi_adjust_cfa_offset (4)
39 cfi_rel_offset (r9, 0)
41 cfi_adjust_cfa_offset (4)
42 cfi_rel_offset (r8, 0)
44 cfi_adjust_cfa_offset (4)
45 cfi_rel_offset (pr, 0)
52 CMPXCHG (r3, @r8, r4, r2)
54 CMPXCHG (r3, @(MUTEX,r8), r4, r2)
58 mov.l @(WRITER,r8), r0
61 mov.l @(WRITERS_QUEUED,r8), r0
69 mov.l @(READERS_QUEUED,r8), r0
71 mov.l r0, @(READERS_QUEUED,r8)
75 mov.l @(READERS_WAKEUP,r8), r9
85 #ifdef __ASSUME_PRIVATE_FUTEX
88 mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAIT), r0
106 add #READERS_WAKEUP, r4
114 /* Reget the lock. */
118 CMPXCHG (r3, @r8, r4, r2)
120 CMPXCHG (r3, @(MUTEX,r8), r4, r2)
124 mov.l @(READERS_QUEUED,r8), r0
127 mov.l r0, @(READERS_QUEUED,r8)
131 mov.l @(NR_READERS,r8), r0
133 mov.l r0, @(NR_READERS,r8)
141 DEC (@(MUTEX,r8), r2)
148 cfi_adjust_cfa_offset (-4)
151 cfi_adjust_cfa_offset (-4)
154 cfi_adjust_cfa_offset (-4)
157 cfi_adjust_cfa_offset (-4)
163 #ifndef __ASSUME_PRIVATE_FUTEX
165 .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
189 /* Deadlock detected. */
194 .word TID - TLS_PRE_TCB_SIZE
213 mov.l @(NR_READERS,r8), r1
215 mov.l r1, @(NR_READERS,r8)
221 mov.l @(READERS_QUEUED,r8), r1
223 mov.l r1, @(READERS_QUEUED,r8)
260 .long __lll_lock_wait-.Lwait0b
262 .long __lll_unlock_wake-.Lwake0b
264 .long __lll_lock_wait-.Lwait1b
266 .long __lll_unlock_wake-.Lwake1b
267 .size __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock
269 strong_alias (__pthread_rwlock_rdlock, pthread_rwlock_rdlock)
270 hidden_def (__pthread_rwlock_rdlock)