1 /* Copyright (C) 2002, 2003, 2007 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>
29 .globl __pthread_rwlock_wrlock
30 .type __pthread_rwlock_wrlock,@function
31 .protected __pthread_rwlock_wrlock
33 __pthread_rwlock_wrlock:
36 cfi_adjust_cfa_offset(4)
38 cfi_adjust_cfa_offset(4)
52 cmpxchgl %edx, MUTEX(%ebx)
56 2: movl WRITER(%ebx), %eax
59 cmpl $0, NR_READERS(%ebx)
62 3: addl $1, WRITERS_QUEUED(%ebx)
65 movl WRITERS_WAKEUP(%ebx), %edx
76 #ifdef __ASSUME_PRIVATE_FUTEX
77 movzbl PSHARED(%ebx), %ecx
78 xorl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %ecx
80 movzbl PSHARED(%ebx), %ecx
84 xorl %gs:PRIVATE_FUTEX, %ecx
86 addl $WRITERS_WAKEUP, %ebx
90 subl $WRITERS_WAKEUP, %ebx
99 cmpxchgl %edx, MUTEX(%ebx)
103 13: subl $1, WRITERS_QUEUED(%ebx)
108 movl %eax, WRITER(%ebx)
120 cfi_adjust_cfa_offset(-4)
123 cfi_adjust_cfa_offset(-4)
127 cfi_adjust_cfa_offset(8)
129 cfi_offset(%ebx, -12)
134 leal MUTEX(%ebx), %edx
136 movzbl PSHARED(%ebx), %ecx
140 14: cmpl %gs:TID , %eax
149 leal MUTEX(%ebx), %eax
151 movzbl PSHARED(%ebx), %ecx
152 call __lll_unlock_wake
155 4: subl $1, WRITERS_QUEUED(%ebx)
163 leal MUTEX(%ebx), %eax
165 movzbl PSHARED(%ebx), %ecx
166 call __lll_unlock_wake
173 leal MUTEX(%ebx), %edx
175 movzbl PSHARED(%ebx), %ecx
179 .size __pthread_rwlock_wrlock,.-__pthread_rwlock_wrlock
181 .globl pthread_rwlock_wrlock
182 pthread_rwlock_wrlock = __pthread_rwlock_wrlock
184 .globl __pthread_rwlock_wrlock_internal
185 __pthread_rwlock_wrlock_internal = __pthread_rwlock_wrlock