X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fthread%2Fpthread_mutex_unlock.c;h=67aa7ba5d14e1e983e25745f8a1104493b413ff8;hb=047e434ef5fd5437a74f98f63c40a77a683f7f3f;hp=0275eb52e6e6a5e93f34a2037e601dbbaaccdfac;hpb=e882756311c7b06e59fcc8e582f03852b7dcfd30;p=musl diff --git a/src/thread/pthread_mutex_unlock.c b/src/thread/pthread_mutex_unlock.c index 0275eb52..67aa7ba5 100644 --- a/src/thread/pthread_mutex_unlock.c +++ b/src/thread/pthread_mutex_unlock.c @@ -2,18 +2,23 @@ int pthread_mutex_unlock(pthread_mutex_t *m) { - if (m->_m_type == PTHREAD_MUTEX_RECURSIVE) { - if (a_fetch_add(&m->_m_lock, -1)==1 && m->_m_waiters) - __wake(&m->_m_lock, 1, 0); - return 0; - } + pthread_t self; - if (m->_m_type == PTHREAD_MUTEX_ERRORCHECK - && m->_m_owner != pthread_self()->tid) - return EPERM; + if (m->_m_type != PTHREAD_MUTEX_NORMAL) { + self = __pthread_self(); + if ((m->_m_lock&0x1fffffff) != self->tid) + return EPERM; + if ((m->_m_type&3) == PTHREAD_MUTEX_RECURSIVE && --m->_m_count) + return 0; + if (m->_m_type >= 4) { + self->robust_list.pending = &m->_m_next; + *(void **)m->_m_prev = m->_m_next; + if (m->_m_next) ((void **)m->_m_next)[-1] = m->_m_prev; + } + } - m->_m_owner = 0; m->_m_lock = 0; if (m->_m_waiters) __wake(&m->_m_lock, 1, 0); + if (m->_m_type >= 4) self->robust_list.pending = 0; return 0; }