1 /* Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 #include <lowlevellock.h>
21 #include <lowlevelbarrier.h>
22 #include "lowlevel-atomic.h"
26 .globl pthread_barrier_wait
27 .type pthread_barrier_wait,@function
38 CMPXCHG (r3, @(MUTEX,r8), r4, r2)
41 /* One less waiter. If this was the last one needed wake
50 /* There are more threads to come. */
51 mov.l @(CURR_EVENT,r8), r6
53 /* Release the mutex. */
58 /* Wait for the remaining threads. The call will return immediately
59 if the CURR_EVENT memory has meanwhile been changed. */
65 mov.l @(PRIVATE,r8), r5
68 mov.l @(PRIVATE,r8), r0
78 /* Don't return on spurious wakeups. The syscall does not change
79 any register except r0 so there is no need to reload any of
81 mov.l @(CURR_EVENT,r8), r0
85 /* Increment LEFT. If this brings the count back to the
86 initial count unlock the object. */
88 mov.l @(INIT_COUNT,r8), r4
89 XADD (r3, @(LEFT,r8), r2, r5)
94 /* Release the mutex. We cannot release the lock before
95 waking the waiting threads since otherwise a new thread might
96 arrive and gets waken up, too. */
102 mov #0, r0 /* != PTHREAD_BARRIER_SERIAL_THREAD */
109 /* The necessary number of threads arrived. */
110 mov.l @(CURR_EVENT,r8), r1
112 mov.l r1, @(CURR_EVENT,r8)
114 /* Wake up all waiters. The count is a signed number in the kernel
115 so 0x7fffffff is the highest value. */
123 mov.l @(PRIVATE,r8), r0
130 /* Increment LEFT. If this brings the count back to the
131 initial count unlock the object. */
133 mov.l @(INIT_COUNT,r8), r4
134 XADD (r3, @(LEFT,r8), r2, r5)
139 /* Release the mutex. */
140 DEC (@(MUTEX,r8), r2)
144 mov #-1, r0 /* == PTHREAD_BARRIER_SERIAL_THREAD */
151 mov.l @(PRIVATE,r8), r6
165 mov.l @(PRIVATE,r8), r5
179 mov.l @(PRIVATE,r8), r5
193 mov.l @(PRIVATE,r8), r5
209 .long __lll_lock_wait-.Lwait0b
211 .long __lll_unlock_wake-.Lwake0b
213 .long __lll_unlock_wake-.Lwake1b
215 .long __lll_unlock_wake-.Lwake2b
216 .size pthread_barrier_wait,.-pthread_barrier_wait