9ns: mnt: Don't use a 'bogus' struct
[akaros.git] / kern / arch / x86 / atomic.h
index eaaa761..dd1a29c 100644 (file)
@@ -4,8 +4,7 @@
  *
  * x86 atomics and locking functions. */
 
-#ifndef ROS_KERN_ARCH_ATOMIC_H
-#define ROS_KERN_ARCH_ATOMIC_H
+#pragma once
 
 #include <ros/common.h>
 #include <ros/arch/membar.h>
@@ -69,6 +68,11 @@ static inline long atomic_swap(atomic_t *addr, long val)
        return (long)__sync_lock_test_and_set(addr, val);
 }
 
+static inline void *atomic_swap_ptr(void **addr, void *val)
+{
+       return (void*)__sync_lock_test_and_set(addr, val);
+}
+
 static inline bool atomic_cas(atomic_t *addr, long exp_val, long new_val)
 {
        return __sync_bool_compare_and_swap(addr, exp_val, new_val);
@@ -127,18 +131,19 @@ static inline bool spin_locked(spinlock_t *lock)
 
 static inline void __spin_lock_raw(volatile uint32_t *rlock)
 {
+       uint8_t dicks = 0;
        asm volatile(
                        "1:                       "
                        "       cmpb $0, %0;          "
                        "       je 2f;                "
                        "       pause;                "
                        "       jmp 1b;               "
-                       "2:                       " 
-                       "       movb $1, %%al;        "
-                       "       xchgb %%al, %0;       "
-                       "       cmpb $0, %%al;        "
+                       "2:                       "
+                       "       movb $1, %1;          "
+                       "       xchgb %1, %0;         "
+                       "       cmpb $0, %1;          "
                        "       jne 1b;               "
-               : : "m"(*rlock) : "eax", "cc");
+               : : "m"(*rlock), "r"(dicks) : "cc");
        cmb();  /* need cmb(), the CPU mb() was handled by the xchg */
 }
 
@@ -166,5 +171,3 @@ static inline void __spinlock_init(spinlock_t *lock)
 {
        lock->rlock = 0;
 }
-
-#endif /* ROS_KERN_ARCH_ATOMIC_H */