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 <lowlevelbarrier.h>
36 .globl pthread_barrier_wait
37 .type pthread_barrier_wait,@function
48 cmpxchgl %edx, MUTEX(%ebx)
51 /* One less waiter. If this was the last one needed wake
53 2: subl $1, LEFT(%ebx)
56 /* There are more threads to come. */
62 movl CURR_EVENT(%ebx), %edx
65 /* Release the mutex. */
70 /* Wait for the remaining threads. The call will return immediately
71 if the CURR_EVENT memory has meanwhile been changed. */
74 movl PRIVATE(%ebx), %ecx
76 movl $FUTEX_WAIT, %ecx
77 orl PRIVATE(%ebx), %ecx
80 8: movl $SYS_futex, %eax
83 /* Don't return on spurious wakeups. The syscall does not change
84 any register except %eax so there is no need to reload any of
89 cmpl %edx, CURR_EVENT(%ebx)
93 /* Increment LEFT. If this brings the count back to the
94 initial count unlock the object. */
96 movl INIT_COUNT(%ebx), %ecx
98 xaddl %edx, LEFT(%ebx)
103 /* Release the mutex. We cannot release the lock before
104 waking the waiting threads since otherwise a new thread might
105 arrive and gets waken up, too. */
110 /* Note: %esi is still zero. */
111 10: movl %esi, %eax /* != PTHREAD_BARRIER_SERIAL_THREAD */
117 /* The necessary number of threads arrived. */
122 addl $1, CURR_EVENT(%ebx)
125 /* Wake up all waiters. The count is a signed number in the kernel
126 so 0x7fffffff is the highest value. */
127 movl $0x7fffffff, %edx
128 movl $FUTEX_WAKE, %ecx
129 orl PRIVATE(%ebx), %ecx
130 movl $SYS_futex, %eax
133 /* Increment LEFT. If this brings the count back to the
134 initial count unlock the object. */
136 movl INIT_COUNT(%ebx), %ecx
138 xaddl %edx, LEFT(%ebx)
143 /* Release the mutex. We cannot release the lock before
144 waking the waiting threads since otherwise a new thread might
145 arrive and gets waken up, too. */
150 5: orl $-1, %eax /* == PTHREAD_BARRIER_SERIAL_THREAD */
155 1: leal MUTEX(%ebx), %ecx
156 call __lll_mutex_lock_wait
159 4: leal MUTEX(%ebx), %eax
160 call __lll_mutex_unlock_wake
163 6: leal MUTEX(%ebx), %eax
164 call __lll_mutex_unlock_wake
167 9: leal MUTEX(%ebx), %eax
168 call __lll_mutex_unlock_wake
170 .size pthread_barrier_wait,.-pthread_barrier_wait