correct error returns for error-checking mutexes

This commit is contained in:
Rich Felker 2011-03-16 16:25:00 -04:00
parent 29fae65780
commit d4f9e0b364
2 changed files with 6 additions and 2 deletions

View 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;
}

View 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;