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_wrlock
30 .type __pthread_rwlock_wrlock,@function
31 .protected __pthread_rwlock_wrlock
33 __pthread_rwlock_wrlock:
44 cmpxchgl %esi, MUTEX(%rdi)
48 2: movl WRITER(%rdi), %eax
51 cmpl $0, NR_READERS(%rdi)
54 3: incl WRITERS_QUEUED(%rdi)
57 movl WRITERS_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 $WRITERS_WAKEUP, %rdi
84 subq $WRITERS_WAKEUP, %rdi
93 cmpxchgl %esi, MUTEX(%rdi)
97 13: decl WRITERS_QUEUED(%rdi)
102 movl %eax, WRITER(%rdi)
115 1: movl PSHARED(%rdi), %esi
119 callq __lll_lock_wait
125 14: cmpl %fs:TID, %eax
130 6: movl PSHARED(%rdi), %esi
134 callq __lll_unlock_wake
137 4: decl WRITERS_QUEUED(%rdi)
141 10: movl PSHARED(%rdi), %esi
145 callq __lll_unlock_wake
151 12: movl PSHARED(%rdi), %esi
155 callq __lll_lock_wait
161 .size __pthread_rwlock_wrlock,.-__pthread_rwlock_wrlock
163 .globl pthread_rwlock_wrlock
164 pthread_rwlock_wrlock = __pthread_rwlock_wrlock
166 .globl __pthread_rwlock_wrlock_internal
167 __pthread_rwlock_wrlock_internal = __pthread_rwlock_wrlock