fix false ownership of mutexes due to tid reuse, using robust list
[musl] / src / thread / pthread_mutex_timedlock.c
index 849febb..2a959d2 100644 (file)
@@ -9,9 +9,10 @@ int pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *
        int r, t, priv = (m->_m_type & 128) ^ 128;
 
        while ((r=pthread_mutex_trylock(m)) == EBUSY) {
-               if (!(r=m->_m_lock) || (r&0x40000000)) continue;
+               if (!(r=m->_m_lock) || ((r&0x40000000) && (m->_m_type&4)))
+                       continue;
                if ((m->_m_type&3) == PTHREAD_MUTEX_ERRORCHECK
-                && (r&0x1fffffff) == __pthread_self()->tid)
+                && (r&0x7fffffff) == __pthread_self()->tid)
                        return EDEADLK;
 
                a_inc(&m->_m_waiters);