From e914f8b7ec79f622fa3b017af434642f61d45ce8 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 17 Mar 2011 12:14:40 -0400 Subject: optimize contended normal mutex case; add int compare-and-swap atomic --- src/thread/pthread_mutex_trylock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') 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; -- cgit v1.2.3-70-g09d2