Lines Matching refs:barrier
38 pthread_barrier_init(pthread_barrier_t *restrict barrier, in pthread_barrier_init() argument
46 if (pthread_mutex_init(&barrier->mutex, 0) < 0) { in pthread_barrier_init()
49 if (pthread_cond_init(&barrier->cond, 0) < 0) { in pthread_barrier_init()
51 pthread_mutex_destroy(&barrier->mutex); in pthread_barrier_init()
56 barrier->limit = count; in pthread_barrier_init()
57 barrier->count = 0; in pthread_barrier_init()
58 barrier->phase = 0; in pthread_barrier_init()
64 pthread_barrier_destroy(pthread_barrier_t *barrier) { in pthread_barrier_destroy() argument
65 pthread_mutex_destroy(&barrier->mutex); in pthread_barrier_destroy()
66 pthread_cond_destroy(&barrier->cond); in pthread_barrier_destroy()
71 pthread_barrier_wait(pthread_barrier_t *barrier) { in pthread_barrier_wait() argument
72 pthread_mutex_lock(&barrier->mutex); in pthread_barrier_wait()
73 barrier->count++; in pthread_barrier_wait()
74 if (barrier->count >= barrier->limit) { in pthread_barrier_wait()
75 barrier->phase++; in pthread_barrier_wait()
76 barrier->count = 0; in pthread_barrier_wait()
77 pthread_cond_broadcast(&barrier->cond); in pthread_barrier_wait()
78 pthread_mutex_unlock(&barrier->mutex); in pthread_barrier_wait()
81 unsigned phase = barrier->phase; in pthread_barrier_wait()
83 pthread_cond_wait(&barrier->cond, &barrier->mutex); in pthread_barrier_wait()
84 while (phase == barrier->phase); in pthread_barrier_wait()
85 pthread_mutex_unlock(&barrier->mutex); in pthread_barrier_wait()