X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fthread%2Fpthread_mutex_unlock.c;h=b66423e6c34f7ac39cf81a122dba3d83eea46f26;hb=a75283d777ed1827ed247dbb465818a0ce371c8f;hp=02da92a96b0b83f44b31ee91803fd74af70ecc6f;hpb=f08ab9e61a147630497198fe3239149275c0a3f4;p=musl diff --git a/src/thread/pthread_mutex_unlock.c b/src/thread/pthread_mutex_unlock.c index 02da92a9..b66423e6 100644 --- a/src/thread/pthread_mutex_unlock.c +++ b/src/thread/pthread_mutex_unlock.c @@ -7,13 +7,19 @@ int __pthread_mutex_unlock(pthread_mutex_t *m) int cont; int type = m->_m_type & 15; int priv = (m->_m_type & 128) ^ 128; + int new = 0; + int old; if (type != PTHREAD_MUTEX_NORMAL) { self = __pthread_self(); - if ((m->_m_lock&0x7fffffff) != self->tid) + old = m->_m_lock; + int own = old & 0x3fffffff; + if (own != self->tid) return EPERM; if ((type&3) == PTHREAD_MUTEX_RECURSIVE && m->_m_count) return m->_m_count--, 0; + if ((type&4) && (old&0x40000000)) + new = 0x7fffffff; if (!priv) { self->robust_list.pending = &m->_m_next; __vm_lock(); @@ -24,7 +30,16 @@ int __pthread_mutex_unlock(pthread_mutex_t *m) if (next != &self->robust_list.head) *(volatile void *volatile *) ((char *)next - sizeof(void *)) = prev; } - cont = a_swap(&m->_m_lock, (type & 8) ? 0x40000000 : 0); + if (type&8) { + if (old<0 || a_cas(&m->_m_lock, old, new)!=old) { + if (new) a_store(&m->_m_waiters, -1); + __syscall(SYS_futex, &m->_m_lock, FUTEX_UNLOCK_PI|priv); + } + cont = 0; + waiters = 0; + } else { + cont = a_swap(&m->_m_lock, new); + } if (type != PTHREAD_MUTEX_NORMAL && !priv) { self->robust_list.pending = 0; __vm_unlock();