correct error returns for error-checking mutexes
authorRich Felker <dalias@aerifal.cx>
Wed, 16 Mar 2011 20:25:00 +0000 (16:25 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 16 Mar 2011 20:25:00 +0000 (16:25 -0400)
src/thread/pthread_mutex_lock.c
src/thread/pthread_mutex_trylock.c

index 15ede3f5abdbe75edac86fdfd6ae8da7688bf472..82556141e463b8a9a0d7ea4f7dcacebf5c296bdd 100644 (file)
@@ -3,7 +3,11 @@
 int pthread_mutex_lock(pthread_mutex_t *m)
 {
        int r;
-       while ((r=pthread_mutex_trylock(m)) == EBUSY)
+       while ((r=pthread_mutex_trylock(m)) == EBUSY) {
+               if (m->_m_type == PTHREAD_MUTEX_ERRORCHECK
+                && m->_m_owner == pthread_self()->tid)
+                       return EDEADLK;
                __wait(&m->_m_lock, &m->_m_waiters, 1, 0);
+       }
        return r;
 }
index 2dad7bbf19a9752368d894f35f59a328bfb1d34c..25b9e869ae02f6621112c3a086d4245ccc70559b 100644 (file)
@@ -11,7 +11,7 @@ int pthread_mutex_trylock(pthread_mutex_t *m)
 
        if (m->_m_owner == tid) {
                if (m->_m_type != PTHREAD_MUTEX_RECURSIVE)
-                       return EDEADLK;
+                       return EBUSY;
                if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN;
                m->_m_count++;
                return 0;