in pthread_mutex_trylock, EBUSY out more directly when possible
authorRich Felker <dalias@aerifal.cx>
Wed, 5 Sep 2018 01:28:38 +0000 (21:28 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 5 Sep 2018 01:28:38 +0000 (21:28 -0400)
avoid gratuitously setting up and tearing down the robust list pending
slot.

src/thread/pthread_mutex_trylock.c

index 54876a619fb1238a3a37dd8346fbbf615152b263..783ca0c40d745053aedc8f92bb16f8e85049125b 100644 (file)
@@ -15,6 +15,7 @@ int __pthread_mutex_trylock_owner(pthread_mutex_t *m)
                return 0;
        }
        if (own == 0x7fffffff) return ENOTRECOVERABLE;
+       if (own && (!(own & 0x40000000) || !(type & 4))) return EBUSY;
 
        if (m->_m_type & 128) {
                if (!self->robust_list.off) {
@@ -25,8 +26,7 @@ int __pthread_mutex_trylock_owner(pthread_mutex_t *m)
                self->robust_list.pending = &m->_m_next;
        }
 
-       if ((own && (!(own & 0x40000000) || !(type & 4)))
-           || a_cas(&m->_m_lock, old, tid) != old) {
+       if (a_cas(&m->_m_lock, old, tid) != old) {
                self->robust_list.pending = 0;
                return EBUSY;
        }