1 /* Copyright (C) 2002, 2003, 2004, 2005 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
44 cmpxchgl %esi, MUTEX(%rdi)
47 /* One less waiter. If this was the last one needed wake
52 /* There are more threads to come. */
56 movl CURR_EVENT(%rdi), %edx
59 /* Release the mutex. */
64 /* Wait for the remaining threads. The call will return immediately
65 if the CURR_EVENT memory has meanwhile been changed. */
70 movl $FUTEX_WAIT, %esi
73 8: movl $SYS_futex, %eax
76 /* Don't return on spurious wakeups. The syscall does not change
77 any register except %eax so there is no need to reload any of
82 cmpl %edx, CURR_EVENT(%rdi)
86 /* Increment LEFT. If this brings the count back to the
87 initial count unlock the object. */
89 movl INIT_COUNT(%rdi), %eax
91 xaddl %edx, LEFT(%rdi)
96 /* Release the mutex. We cannot release the lock before
97 waking the waiting threads since otherwise a new thread might
98 arrive and gets waken up, too. */
103 10: xorl %eax, %eax /* != PTHREAD_BARRIER_SERIAL_THREAD */
107 /* The necessary number of threads arrived. */
112 incl CURR_EVENT(%rdi)
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, %esi
119 movl $SYS_futex, %eax
122 /* Increment LEFT. If this brings the count back to the
123 initial count unlock the object. */
125 movl INIT_COUNT(%rdi), %eax
127 xaddl %edx, LEFT(%rdi)
132 /* Release the mutex. We cannot release the lock before
133 waking the waiting threads since otherwise a new thread might
134 arrive and gets waken up, too. */
139 5: orl $-1, %eax /* == PTHREAD_BARRIER_SERIAL_THREAD */
144 callq __lll_mutex_lock_wait
149 callq __lll_mutex_unlock_wake
153 callq __lll_mutex_unlock_wake
158 callq __lll_mutex_unlock_wake
160 .size pthread_barrier_wait,.-pthread_barrier_wait