Fixes spin_trylock()
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 8 Oct 2013 17:23:07 +0000 (10:23 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 16 Jan 2014 02:23:22 +0000 (18:23 -0800)
Was returning TRUE on failure, instead of on success.

kern/arch/riscv/atomic.h
kern/arch/x86/atomic.h

index 8ba30a6..7ba7f2c 100644 (file)
@@ -131,7 +131,7 @@ static inline bool spin_locked(spinlock_t* lock)
 
 static inline bool __spin_trylock(spinlock_t *lock)
 {
-       return __sync_fetch_and_or(&lock->rlock, 1);
+       return !__sync_fetch_and_or(&lock->rlock, 1);
 }
 
 static inline void __spin_lock(spinlock_t *lock)
@@ -140,7 +140,7 @@ static inline void __spin_lock(spinlock_t *lock)
        {
                while (lock->rlock)
                        ;
-       } while (__spin_trylock(lock));
+       } while (!__spin_trylock(lock));
        mb();
 }
 
index 29a11e1..eaaa761 100644 (file)
@@ -151,7 +151,7 @@ static inline bool __spin_trylock(spinlock_t *lock)
 {
        /* since this is an or, we're not going to clobber the top bytes (if that
         * matters) */
-       return __sync_fetch_and_or(&lock->rlock, 1);
+       return !__sync_fetch_and_or(&lock->rlock, 1);
 }
 
 static inline void __spin_unlock(spinlock_t *lock)