optimize contended case for pthread_spin_trylock
authorRich Felker <dalias@aerifal.cx>
Fri, 25 Mar 2011 03:06:08 +0000 (23:06 -0400)
committerRich Felker <dalias@aerifal.cx>
Fri, 25 Mar 2011 03:06:08 +0000 (23:06 -0400)
src/thread/pthread_spin_trylock.c

index c12696b..1fc5f73 100644 (file)
@@ -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;
 }