提交 e914f8b7 编写于 作者: R Rich Felker

optimize contended normal mutex case; add int compare-and-swap atomic

上级 1d59f1ed
......@@ -49,6 +49,13 @@ static inline long a_cas_l(volatile void *p, long t, long s)
return t;
}
static inline int a_cas(volatile int *p, int t, int s)
{
__asm__( "lock ; cmpxchg %3, %1"
: "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
return t;
}
static inline void *a_swap_p(void *volatile *x, void *v)
{
__asm__( "xchg %0, %1" : "=r"(v), "=m"(*(void **)x) : "0"(v) : "memory" );
......
......@@ -48,6 +48,13 @@ static inline long a_cas_l(volatile void *p, long t, long s)
return t;
}
static inline int a_cas(volatile int *p, int t, int s)
{
__asm__( "lock ; cmpxchgl %3, %1"
: "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
return t;
}
static inline void *a_swap_p(void *volatile *x, void *v)
{
__asm__( "xchg %0, %1" : "=r"(v), "=m"(*(void **)x) : "0"(v) : "memory" );
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册