about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-24 23:06:08 -0400
committerRich Felker <dalias@aerifal.cx>2011-03-24 23:06:08 -0400
commitb8b85a42729dc96e43d51848823fbe28ad92b5c0 (patch)
treee4283410cf7a5da198ca1171c240b78ac76adbb3
parentc322fe4e1a9bcc20f7a2ded1ac0e1674ea282bc0 (diff)
downloadmusl-b8b85a42729dc96e43d51848823fbe28ad92b5c0.tar.gz
musl-b8b85a42729dc96e43d51848823fbe28ad92b5c0.tar.xz
musl-b8b85a42729dc96e43d51848823fbe28ad92b5c0.zip
optimize contended case for pthread_spin_trylock
-rw-r--r--src/thread/pthread_spin_trylock.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/thread/pthread_spin_trylock.c b/src/thread/pthread_spin_trylock.c
index c12696b3..1fc5f73c 100644
--- a/src/thread/pthread_spin_trylock.c
+++ b/src/thread/pthread_spin_trylock.c
@@ -2,5 +2,6 @@
 
 int pthread_spin_trylock(pthread_spinlock_t *s)
 {
-	return -a_xchg(s, 1) & EBUSY;
+	if (*s || a_xchg(s, 1)) return EBUSY;
+	return 0;
 }