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 */
25 a_fetch_add(&m->_m_waiters, c->_c_waiters2);
28 /* Perform the futex requeue, waking one waiter unless we know
29 * that the calling thread holds the mutex. */
30 __syscall(SYS_futex, &c->_c_seq, FUTEX_REQUEUE,
31 !m->_m_type || (m->_m_lock&INT_MAX)!=pthread_self()->tid,
32 INT_MAX, &m->_m_lock);
35 a_store(&c->_c_lock, 0);
36 if (c->_c_lockwait) __wake(&c->_c_lock, 1, 0);