Undo last change. Add asflags-cpu to ASFLAGS in the same place we add
[glibc/history.git] / nptl / DESIGN-barrier.txt
blob23463c6b7e77231697db3e13933b36ce295365b1
1 Barriers pseudocode
2 ===================
4     int pthread_barrier_wait(barrier_t *barrier);
6 struct barrier_t {
8    unsigned int lock:
9          - internal mutex
11    unsigned int left;
12          - current barrier count, # of threads still needed.
14    unsigned int init_count;
15          - number of threads needed for the barrier to continue.
17    unsigned int curr_event;
18          - generation count
21 pthread_barrier_wait(barrier_t *barrier)
23   unsigned int event;
24   result = 0;
26   lll_lock(barrier->lock);
27   if (!--barrier->left) {
28     barrier->curr_event++;
29     futex_wake(&barrier->curr_event, INT_MAX)
31     result = BARRIER_SERIAL_THREAD;
32   } else {
33     event = barrier->curr_event;
34     lll_unlock(barrier->lock);
35     do {
36       futex_wait(&barrier->curr_event, event)
37     } while (event == barrier->curr_event);
38   }
40   if (atomic_increment_val (barrier->left) == barrier->init_count)
41     lll_unlock(barrier->lock);
43   return result;