mirror of
git://sourceware.org/git/glibc.git
synced 2024-12-03 04:01:43 +08:00
37c054c7c4
* sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S (pthread_barrier_wait): After wakeup, release lock only when the last thread stopped using the barrier object. * sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S (pthread_barrier_wait): Likewise. * sysdeps/pthread/pthread_barrier_wait.c (pthread_barrier_wait): Likewise. * Makefile (tests): Add tst-barrier4. * tst-barrier4.c: New file.
48 lines
983 B
Plaintext
48 lines
983 B
Plaintext
Barriers pseudocode
|
|
===================
|
|
|
|
int pthread_barrier_wait(barrier_t *barrier);
|
|
|
|
struct barrier_t {
|
|
|
|
unsigned int lock:
|
|
- internal mutex
|
|
|
|
unsigned int left;
|
|
- current barrier count, # of threads still needed.
|
|
|
|
unsigned int init_count;
|
|
- number of threads needed for the barrier to continue.
|
|
|
|
unsigned int curr_event;
|
|
- generation count
|
|
}
|
|
|
|
pthread_barrier_wait(barrier_t *barrier)
|
|
{
|
|
unsigned int event;
|
|
result = 0;
|
|
|
|
lll_lock(barrier->lock);
|
|
if (!--barrier->left) {
|
|
barrier->curr_event++;
|
|
futex_wake(&barrier->curr_event, INT_MAX)
|
|
|
|
result = BARRIER_SERIAL_THREAD;
|
|
} else {
|
|
event = barrier->curr_event;
|
|
do {
|
|
lll_unlock(barrier->lock);
|
|
|
|
futex_wait(&barrier->curr_event, event)
|
|
|
|
lll_lock(barrier->lock);
|
|
} while (event == barrier->curr_event);
|
|
}
|
|
|
|
if (atomic_exchange_and_add (barrier->left, 1) == barrier->init_count - 1)
|
|
lll_unlock(barrier->lock);
|
|
|
|
return result;
|
|
}
|