1 /* Copyright (C) 2002, 2003, 2004, 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <lowlevellock.h>
22 #include <lowlevelbarrier.h>
26 .globl pthread_barrier_wait
27 .type pthread_barrier_wait,@function
38 cmpxchgl %edx, MUTEX(%ebx)
41 /* One less waiter. If this was the last one needed wake
43 2: subl $1, LEFT(%ebx)
46 /* There are more threads to come. */
52 movl CURR_EVENT(%ebx), %edx
55 /* Release the mutex. */
60 /* Wait for the remaining threads. The call will return immediately
61 if the CURR_EVENT memory has meanwhile been changed. */
64 movl PRIVATE(%ebx), %ecx
66 movl $FUTEX_WAIT, %ecx
67 orl PRIVATE(%ebx), %ecx
70 8: movl $SYS_futex, %eax
73 /* Don't return on spurious wakeups. The syscall does not change
74 any register except %eax so there is no need to reload any of
79 cmpl %edx, CURR_EVENT(%ebx)
83 /* Increment LEFT. If this brings the count back to the
84 initial count unlock the object. */
86 movl INIT_COUNT(%ebx), %ecx
88 xaddl %edx, LEFT(%ebx)
93 /* Release the mutex. We cannot release the lock before
94 waking the waiting threads since otherwise a new thread might
95 arrive and gets waken up, too. */
100 /* Note: %esi is still zero. */
101 10: movl %esi, %eax /* != PTHREAD_BARRIER_SERIAL_THREAD */
107 /* The necessary number of threads arrived. */
112 addl $1, CURR_EVENT(%ebx)
115 /* Wake up all waiters. The count is a signed number in the kernel
116 so 0x7fffffff is the highest value. */
117 movl $0x7fffffff, %edx
118 movl $FUTEX_WAKE, %ecx
119 orl PRIVATE(%ebx), %ecx
120 movl $SYS_futex, %eax
123 /* Increment LEFT. If this brings the count back to the
124 initial count unlock the object. */
126 movl INIT_COUNT(%ebx), %ecx
128 xaddl %edx, LEFT(%ebx)
133 /* Release the mutex. We cannot release the lock before
134 waking the waiting threads since otherwise a new thread might
135 arrive and gets waken up, too. */
140 5: orl $-1, %eax /* == PTHREAD_BARRIER_SERIAL_THREAD */
145 1: movl PRIVATE(%ebx), %ecx
146 leal MUTEX(%ebx), %edx
147 xorl $LLL_SHARED, %ecx
151 4: movl PRIVATE(%ebx), %ecx
152 leal MUTEX(%ebx), %eax
153 xorl $LLL_SHARED, %ecx
154 call __lll_unlock_wake
157 6: movl PRIVATE(%ebx), %ecx
158 leal MUTEX(%ebx), %eax
159 xorl $LLL_SHARED, %ecx
160 call __lll_unlock_wake
163 9: movl PRIVATE(%ebx), %ecx
164 leal MUTEX(%ebx), %eax
165 xorl $LLL_SHARED, %ecx
166 call __lll_unlock_wake
168 .size pthread_barrier_wait,.-pthread_barrier_wait