refrain from spinning on locks when there is already a waiter
[musl] / src / thread / pthread_mutex_timedlock.c
index 116a8b7..ae883f9 100644 (file)
@@ -12,7 +12,7 @@ int pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *
        if (r != EBUSY) return r;
        
        int spins = 100;
-       while (spins-- && m->_m_lock) a_spin();
+       while (spins-- && m->_m_lock && !m->_m_waiters) a_spin();
 
        while ((r=pthread_mutex_trylock(m)) == EBUSY) {
                if (!(r=m->_m_lock) || ((r&0x40000000) && (m->_m_type&4)))