reorganize pthread data structures and move the definitions to alltypes.h
[musl] / src / thread / pthread_mutex_unlock.c
1 #include "pthread_impl.h"
2
3 int pthread_mutex_unlock(pthread_mutex_t *m)
4 {
5         if (m->_m_type == PTHREAD_MUTEX_RECURSIVE) {
6                 if (a_fetch_add(&m->_m_lock, -1)==1 && m->_m_waiters)
7                         __wake(&m->_m_lock, 1, 0);
8                 return 0;
9         }
10
11         if (m->_m_type == PTHREAD_MUTEX_ERRORCHECK
12          && m->_m_owner != pthread_self()->tid)
13                 return EPERM;
14
15         m->_m_owner = 0;
16         m->_m_lock = 0;
17         if (m->_m_waiters) __wake(&m->_m_lock, 1, 0);
18         return 0;
19 }