1 #include "pthread_impl.h"
3 int __pthread_mutex_unlock(pthread_mutex_t *m)
6 int waiters = m->_m_waiters;
8 int type = m->_m_type & 15;
9 int priv = (m->_m_type & 128) ^ 128;
12 if (type != PTHREAD_MUTEX_NORMAL) {
13 self = __pthread_self();
15 int own = old & 0x3fffffff;
18 if ((type&3) == PTHREAD_MUTEX_RECURSIVE && m->_m_count)
19 return m->_m_count--, 0;
20 if ((type&4) && (old&0x40000000))
23 self->robust_list.pending = &m->_m_next;
26 volatile void *prev = m->_m_prev;
27 volatile void *next = m->_m_next;
28 *(volatile void *volatile *)prev = next;
29 if (next != &self->robust_list.head) *(volatile void *volatile *)
30 ((char *)next - sizeof(void *)) = prev;
32 cont = a_swap(&m->_m_lock, new);
33 if (type != PTHREAD_MUTEX_NORMAL && !priv) {
34 self->robust_list.pending = 0;
37 if (waiters || cont<0)
38 __wake(&m->_m_lock, 1, priv);
42 weak_alias(__pthread_mutex_unlock, pthread_mutex_unlock);