Virtualization changes to handle X2APIC mode.
[akaros.git] / kern / arch / riscv / atomic.h
index 8ba30a6..e57815d 100644 (file)
@@ -1,5 +1,4 @@
-#ifndef ROS_KERN_ARCH_ATOMIC_H
-#define ROS_KERN_ARCH_ATOMIC_H
+#pragma once
 
 #include <ros/common.h>
 #include <arch/arch.h>
@@ -131,7 +130,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 +139,7 @@ static inline void __spin_lock(spinlock_t *lock)
        {
                while (lock->rlock)
                        ;
-       } while (__spin_trylock(lock));
+       } while (!__spin_trylock(lock));
        mb();
 }
 
@@ -154,5 +153,3 @@ static inline void __spinlock_init(spinlock_t *lock)
 {
        lock->rlock = 0;
 }
-
-#endif /* ROS_KERN_ARCH_ATOMIC_H */