1 #ifndef ARCH_SMP_SPINLOCK_H
2 #define ARCH_SMP_SPINLOCK_H
5 * Your basic SMP spinlocks, allowing only a single CPU anywhere
9 volatile unsigned int lock;
13 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 1 }
14 #define DECLARE_SPIN_LOCK(x) static spinlock_t x = SPIN_LOCK_UNLOCKED;
17 * Simple spin lock operations. There are two variants, one clears IRQ's
18 * on the local processor, one does not.
20 * We make no fairness assumptions. They have a cost.
22 #define barrier() __asm__ __volatile__("": : :"memory")
23 #define spin_is_locked(x) (*(volatile char *)(&(x)->lock) <= 0)
24 #define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x))
26 #define spin_lock_string \
28 "lock ; decb %0\n\t" \
30 ".section .text.lock,\"ax\"\n" \
39 * This works. Despite all the confusion.
41 #define spin_unlock_string \
44 static inline __attribute__((always_inline)) void spin_lock(spinlock_t *lock)
48 :"=m" (lock->lock) : : "memory");
51 static inline __attribute__((always_inline)) void spin_unlock(spinlock_t *lock)
55 :"=m" (lock->lock) : : "memory");
58 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
59 static inline __attribute__((always_inline)) void cpu_relax(void)
61 __asm__ __volatile__("rep;nop": : :"memory");
64 #endif /* ARCH_SMP_SPINLOCK_H */