revert some more spin optimizations that turned out to be pessimizations
authorRich Felker <dalias@aerifal.cx>
Tue, 29 Mar 2011 02:36:55 +0000 (22:36 -0400)
committerRich Felker <dalias@aerifal.cx>
Tue, 29 Mar 2011 02:36:55 +0000 (22:36 -0400)
src/stdio/__lockfile.c
src/thread/pthread_spin_lock.c
src/thread/pthread_spin_trylock.c

index 93c9486..c094825 100644 (file)
@@ -13,7 +13,7 @@ void __lockfile(FILE *f)
                f->lockcount++;
                return;
        }
-       while (f->lock || a_cas(&f->lock, 0, tid))
+       while (a_cas(&f->lock, 0, tid))
                if (spins) spins--, a_spin();
                else syscall(SYS_sched_yield);
        f->lockcount = 1;
index 59fa6ea..0ab3d64 100644 (file)
@@ -2,6 +2,6 @@
 
 int pthread_spin_lock(pthread_spinlock_t *s)
 {
-       while (a_xchg(s, 1));
+       while (a_xchg(s, 1)) a_spin();
        return 0;
 }
index 1fc5f73..c12696b 100644 (file)
@@ -2,6 +2,5 @@
 
 int pthread_spin_trylock(pthread_spinlock_t *s)
 {
-       if (*s || a_xchg(s, 1)) return EBUSY;
-       return 0;
+       return -a_xchg(s, 1) & EBUSY;
 }