dummy implementation of set_thread_area
[musl] / src / thread / pthread_mutex_unlock.c
1 #include "pthread_impl.h"
2
3 int pthread_mutex_unlock(pthread_mutex_t *m)
4 {
5         pthread_t self;
6         int waiters = m->_m_waiters;
7         int cont;
8
9         if (m->_m_type != PTHREAD_MUTEX_NORMAL) {
10                 if (!m->_m_lock)
11                         return EPERM;
12                 self = __pthread_self();
13                 if ((m->_m_lock&0x1fffffff) != self->tid)
14                         return EPERM;
15                 if ((m->_m_type&3) == PTHREAD_MUTEX_RECURSIVE && --m->_m_count)
16                         return 0;
17                 if (m->_m_type >= 4) {
18                         self->robust_list.pending = &m->_m_next;
19                         *(void **)m->_m_prev = m->_m_next;
20                         if (m->_m_next) ((void **)m->_m_next)[-1] = m->_m_prev;
21                         cont = a_swap(&m->_m_lock, 0);
22                         self->robust_list.pending = 0;
23                         goto wake;
24                 }
25         }
26         cont = a_swap(&m->_m_lock, 0);
27 wake:
28         if (waiters || cont<0)
29                 __wake(&m->_m_lock, 1, 0);
30         return 0;
31 }