diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-03-17 12:14:40 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-03-17 12:14:40 -0400 |
commit | e914f8b7ec79f622fa3b017af434642f61d45ce8 (patch) | |
tree | dfba95ae52b2a5998269f7296bef97aa9fce47c4 /src/thread | |
parent | 1d59f1eddbcca03063cf080ded6df13170adcb23 (diff) | |
download | musl-e914f8b7ec79f622fa3b017af434642f61d45ce8.tar.gz musl-e914f8b7ec79f622fa3b017af434642f61d45ce8.tar.xz musl-e914f8b7ec79f622fa3b017af434642f61d45ce8.zip |
optimize contended normal mutex case; add int compare-and-swap atomic
Diffstat (limited to 'src/thread')
-rw-r--r-- | src/thread/pthread_mutex_trylock.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/thread/pthread_mutex_trylock.c b/src/thread/pthread_mutex_trylock.c index af421472..6fc604fe 100644 --- a/src/thread/pthread_mutex_trylock.c +++ b/src/thread/pthread_mutex_trylock.c @@ -5,7 +5,7 @@ int pthread_mutex_trylock(pthread_mutex_t *m) int tid; if (m->_m_type == PTHREAD_MUTEX_NORMAL) - return -a_xchg(&m->_m_lock, 1) & EBUSY; + return (m->_m_lock || a_swap(&m->_m_lock, 1)) ? EBUSY : 0; tid = pthread_self()->tid; |