avoid function call to pthread_self in mutex unlock
[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_NORMAL) {
6                 if (!m->_m_lock || m->_m_lock != __pthread_self()->tid)
7                         return EPERM;
8                 if (m->_m_type == PTHREAD_MUTEX_RECURSIVE && --m->_m_count)
9                         return 0;
10         }
11
12         m->_m_lock = 0;
13         if (m->_m_waiters) __wake(&m->_m_lock, 1, 0);
14         return 0;
15 }