- /* If the waiter count is zero, it must be the case that the
- * caller's count has been moved to the mutex due to bcast. */
- do w = c->_c_waiters;
- while (w && a_cas(&c->_c_waiters, w, w-1)!=w);
- if (!w) a_dec(&m->_m_waiters);
+ while (a_swap(&c->_c_lock, 1))
+ __wait(&c->_c_lock, &c->_c_lockwait, 1, 1);
+
+ if (c->_c_waiters2) c->_c_waiters2--;
+ else a_dec(&m->_m_waiters);
+
+ a_store(&c->_c_lock, 0);
+ if (c->_c_lockwait) __wake(&c->_c_lock, 1, 1);
+
+ a_dec(&c->_c_waiters);
+ if (c->_c_destroy) __wake(&c->_c_waiters, 1, 1);