summaryrefslogtreecommitdiff
path: root/src/thread/pthread_mutex_trylock.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-16 16:49:42 -0400
committerRich Felker <dalias@aerifal.cx>2011-03-16 16:49:42 -0400
commit1d59f1eddbcca03063cf080ded6df13170adcb23 (patch)
tree6fa97ba4a311717774e10ffc5b466f436f69a746 /src/thread/pthread_mutex_trylock.c
parentd4f9e0b3642a81d07c95302cd9aa0dcaf7de1a05 (diff)
downloadmusl-1d59f1eddbcca03063cf080ded6df13170adcb23.tar.gz
simplify logic, slightly optimize contended case for non-default mutex types
Diffstat (limited to 'src/thread/pthread_mutex_trylock.c')
-rw-r--r--src/thread/pthread_mutex_trylock.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/thread/pthread_mutex_trylock.c b/src/thread/pthread_mutex_trylock.c
index 25b9e869..af421472 100644
--- a/src/thread/pthread_mutex_trylock.c
+++ b/src/thread/pthread_mutex_trylock.c
@@ -9,15 +9,13 @@ int pthread_mutex_trylock(pthread_mutex_t *m)
tid = pthread_self()->tid;
- if (m->_m_owner == tid) {
- if (m->_m_type != PTHREAD_MUTEX_RECURSIVE)
- return EBUSY;
+ if (m->_m_owner == tid && m->_m_type == PTHREAD_MUTEX_RECURSIVE) {
if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN;
m->_m_count++;
return 0;
}
- if (a_xchg(&m->_m_lock, 1)) return EBUSY;
+ if (m->_m_owner || a_xchg(&m->_m_lock, 1)) return EBUSY;
m->_m_owner = tid;
m->_m_count = 1;
return 0;