1 /* Copyright (C) 2003, 2007 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 #include <lowlevellock.h>
21 #include <lowlevelrwlock.h>
22 #include <pthread-errnos.h>
23 #include <tcb-offsets.h>
24 #include <bits/kernel-features.h>
25 #include "lowlevel-atomic.h"
30 .globl __pthread_rwlock_rdlock
31 .type __pthread_rwlock_rdlock,@function
32 .protected __pthread_rwlock_rdlock
34 __pthread_rwlock_rdlock:
45 CMPXCHG (r3, @r8, r4, r2)
47 CMPXCHG (r3, @(MUTEX,r8), r4, r2)
51 mov.l @(WRITER,r8), r0
54 mov.l @(WRITERS_QUEUED,r8), r0
62 mov.l @(READERS_QUEUED,r8), r0
64 mov.l r0, @(READERS_QUEUED,r8)
68 mov.l @(READERS_WAKEUP,r8), r9
78 #ifdef __ASSUME_PRIVATE_FUTEX
81 mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAIT), r0
99 add #READERS_WAKEUP, r4
107 /* Reget the lock. */
111 CMPXCHG (r3, @r8, r4, r2)
113 CMPXCHG (r3, @(MUTEX,r8), r4, r2)
117 mov.l @(READERS_QUEUED,r8), r0
120 mov.l r0, @(READERS_QUEUED,r8)
124 mov.l @(NR_READERS,r8), r0
126 mov.l r0, @(NR_READERS,r8)
134 DEC (@(MUTEX,r8), r2)
146 #ifndef __ASSUME_PRIVATE_FUTEX
148 .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
172 /* Deadlock detected. */
177 .word TID - TLS_PRE_TCB_SIZE
196 mov.l @(NR_READERS,r8), r1
198 mov.l r1, @(NR_READERS,r8)
204 mov.l @(READERS_QUEUED,r8), r1
206 mov.l r1, @(READERS_QUEUED,r8)
242 .long __lll_lock_wait-.Lwait0b
244 .long __lll_unlock_wake-.Lwake0b
246 .long __lll_lock_wait-.Lwait1b
248 .long __lll_unlock_wake-.Lwake1b
249 .size __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock
251 .globl pthread_rwlock_rdlock
252 pthread_rwlock_rdlock = __pthread_rwlock_rdlock
254 .globl __pthread_rwlock_rdlock_internal
255 __pthread_rwlock_rdlock_internal = __pthread_rwlock_rdlock