1 /* Copyright (C) 2002, 2003, 2004, 2005, 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>
27 .globl pthread_barrier_wait
28 .type pthread_barrier_wait,@function
35 cmpxchgl %esi, MUTEX(%rdi)
38 /* One less waiter. If this was the last one needed wake
43 /* There are more threads to come. */
47 movl CURR_EVENT(%rdi), %edx
50 /* Release the mutex. */
55 /* Wait for the remaining threads. The call will return immediately
56 if the CURR_EVENT memory has meanwhile been changed. */
59 movl PRIVATE(%rdi), %esi
61 movl $FUTEX_WAIT, %esi
62 orl PRIVATE(%rdi), %esi
65 8: movl $SYS_futex, %eax
68 /* Don't return on spurious wakeups. The syscall does not change
69 any register except %eax so there is no need to reload any of
74 cmpl %edx, CURR_EVENT(%rdi)
78 /* Increment LEFT. If this brings the count back to the
79 initial count unlock the object. */
81 movl INIT_COUNT(%rdi), %eax
83 xaddl %edx, LEFT(%rdi)
88 /* Release the mutex. We cannot release the lock before
89 waking the waiting threads since otherwise a new thread might
90 arrive and gets waken up, too. */
95 10: xorl %eax, %eax /* != PTHREAD_BARRIER_SERIAL_THREAD */
99 /* The necessary number of threads arrived. */
104 incl CURR_EVENT(%rdi)
107 /* Wake up all waiters. The count is a signed number in the kernel
108 so 0x7fffffff is the highest value. */
109 movl $0x7fffffff, %edx
110 movl $FUTEX_WAKE, %esi
111 orl PRIVATE(%rdi), %esi
112 movl $SYS_futex, %eax
115 /* Increment LEFT. If this brings the count back to the
116 initial count unlock the object. */
118 movl INIT_COUNT(%rdi), %eax
120 xaddl %edx, LEFT(%rdi)
125 /* Release the mutex. We cannot release the lock before
126 waking the waiting threads since otherwise a new thread might
127 arrive and gets waken up, too. */
132 5: orl $-1, %eax /* == PTHREAD_BARRIER_SERIAL_THREAD */
136 1: movl PRIVATE(%rdi), %esi
138 xorl $LLL_SHARED, %esi
139 callq __lll_lock_wait
143 4: movl PRIVATE(%rdi), %esi
145 xorl $LLL_SHARED, %esi
146 callq __lll_unlock_wake
149 6: movl PRIVATE(%rdi), %esi
151 xorl $LLL_SHARED, %esi
152 callq __lll_unlock_wake
156 9: movl PRIVATE(%rdi), %esi
158 xorl $LLL_SHARED, %esi
159 callq __lll_unlock_wake
161 .size pthread_barrier_wait,.-pthread_barrier_wait