1 /* Copyright (C) 2002-2015 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 <lowlevelbarrier.h>
26 .globl pthread_barrier_wait
27 .type pthread_barrier_wait,@function
34 cmpxchgl %esi, MUTEX(%rdi)
37 /* One less waiter. If this was the last one needed wake
42 /* There are more threads to come. */
46 movl CURR_EVENT(%rdi), %edx
49 /* Release the mutex. */
54 /* Wait for the remaining threads. The call will return immediately
55 if the CURR_EVENT memory has meanwhile been changed. */
58 movl PRIVATE(%rdi), %esi
60 movl $FUTEX_WAIT, %esi
61 orl PRIVATE(%rdi), %esi
64 8: movl $SYS_futex, %eax
67 /* Don't return on spurious wakeups. The syscall does not change
68 any register except %eax so there is no need to reload any of
73 cmpl %edx, CURR_EVENT(%rdi)
77 /* Increment LEFT. If this brings the count back to the
78 initial count unlock the object. */
80 movl INIT_COUNT(%rdi), %eax
82 xaddl %edx, LEFT(%rdi)
87 /* Release the mutex. We cannot release the lock before
88 waking the waiting threads since otherwise a new thread might
89 arrive and gets waken up, too. */
94 10: xorl %eax, %eax /* != PTHREAD_BARRIER_SERIAL_THREAD */
98 /* The necessary number of threads arrived. */
103 incl CURR_EVENT(%rdi)
106 /* Wake up all waiters. The count is a signed number in the kernel
107 so 0x7fffffff is the highest value. */
108 movl $0x7fffffff, %edx
109 movl $FUTEX_WAKE, %esi
110 orl PRIVATE(%rdi), %esi
111 movl $SYS_futex, %eax
114 /* Increment LEFT. If this brings the count back to the
115 initial count unlock the object. */
117 movl INIT_COUNT(%rdi), %eax
119 xaddl %edx, LEFT(%rdi)
124 /* Release the mutex. We cannot release the lock before
125 waking the waiting threads since otherwise a new thread might
126 arrive and gets waken up, too. */
131 5: orl $-1, %eax /* == PTHREAD_BARRIER_SERIAL_THREAD */
135 1: movl PRIVATE(%rdi), %esi
137 xorl $LLL_SHARED, %esi
138 callq __lll_lock_wait
142 4: movl PRIVATE(%rdi), %esi
144 xorl $LLL_SHARED, %esi
145 callq __lll_unlock_wake
148 6: movl PRIVATE(%rdi), %esi
150 xorl $LLL_SHARED, %esi
151 callq __lll_unlock_wake
155 9: movl PRIVATE(%rdi), %esi
157 xorl $LLL_SHARED, %esi
158 callq __lll_unlock_wake
160 .size pthread_barrier_wait,.-pthread_barrier_wait