#include "pthread_impl.h" #include int mtx_unlock(mtx_t *m) { if ((m->_m_type&3) == PTHREAD_MUTEX_RECURSIVE && m->_m_count) { if ((m->_m_lock&0x1fffffff) != __pthread_self()->tid) return thrd_error; /* _m_count is the count of additional locks, no need to real unlock */ --m->_m_count; } else { if (a_swap(&m->_m_lock, 0)<0 || m->_m_waiters) __wake(&m->_m_lock, 1, 0); } return thrd_success; }