avoid function call to pthread_self in mutex unlock
authorRich Felker <dalias@aerifal.cx>
Thu, 17 Mar 2011 17:35:08 +0000 (13:35 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 17 Mar 2011 17:35:08 +0000 (13:35 -0400)
if the mutex was previously locked, we can assume pthread_self was
already called at the time of locking, and thus that the thread
pointer is initialized.

src/thread/pthread_mutex_unlock.c

index 61a2b9471b52615ef58e858f29095ed85115be16..3733788d8ebee7a375d54db6959aef1f8702a623 100644 (file)
@@ -3,7 +3,7 @@
 int pthread_mutex_unlock(pthread_mutex_t *m)
 {
        if (m->_m_type != PTHREAD_MUTEX_NORMAL) {
-               if (m->_m_lock != pthread_self()->tid)
+               if (!m->_m_lock || m->_m_lock != __pthread_self()->tid)
                        return EPERM;
                if (m->_m_type == PTHREAD_MUTEX_RECURSIVE && --m->_m_count)
                        return 0;