1 #include "pthread_impl.h"
3 int pthread_cond_broadcast(pthread_cond_t *c)
7 if (!c->_c_waiters) return 0;
11 /* If cond var is process-shared, simply wake all waiters. */
12 if (c->_c_mutex == (void *)-1) {
13 __wake(&c->_c_seq, -1, 0);
17 /* Block waiters from returning so we can use the mutex. */
18 while (a_swap(&c->_c_lock, 1))
19 __wait(&c->_c_lock, &c->_c_lockwait, 1, 1);
24 /* Move waiter count to the mutex */
26 int w = c->_c_waiters2;
27 a_fetch_add(&m->_m_waiters, w);
28 if (a_cas(&c->_c_waiters2, w, 0) == w) break;
29 a_fetch_add(&m->_m_waiters, -w);
32 /* Perform the futex requeue, waking one waiter unless we know
33 * that the calling thread holds the mutex. */
34 __syscall(SYS_futex, &c->_c_seq, FUTEX_REQUEUE,
35 !m->_m_type || (m->_m_lock&INT_MAX)!=pthread_self()->tid,
36 INT_MAX, &m->_m_lock);
39 a_store(&c->_c_lock, 0);
40 if (c->_c_lockwait) __wake(&c->_c_lock, 1, 0);