1 #ifndef __ASM_SPINLOCK_H
2 #define __ASM_SPINLOCK_H
4 #include <asm/system.h>
7 * Simple spin lock operations.
9 * (the type definitions are in asm/raw_spinlock_types.h)
12 #define __raw_spin_is_locked(x) ((x)->slock != 0)
13 #define __raw_spin_unlock_wait(lock) \
14 do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0)
15 #define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
17 static inline void __raw_spin_lock(raw_spinlock_t *lock)
22 "b 1f # __raw_spin_lock\n\
34 : "r"(&lock->slock), "r"(1)
38 static inline void __raw_spin_unlock(raw_spinlock_t *lock)
40 __asm__ __volatile__("eieio # __raw_spin_unlock": : :"memory");
44 #define __raw_spin_trylock(l) (!test_and_set_bit(0,(volatile unsigned long *)(&(l)->slock)))
47 * Read-write spinlocks, allowing multiple readers
48 * but only one writer.
50 * NOTE! it is quite common to have readers in interrupts
51 * but no interrupt writers. For those circumstances we
52 * can "mix" irq-safe locks - any writer needs to get a
53 * irq-safe write-lock, but readers can get non-irqsafe
57 #define __raw_read_can_lock(rw) ((rw)->lock >= 0)
58 #define __raw_write_can_lock(rw) (!(rw)->lock)
60 static __inline__ int __raw_read_trylock(raw_rwlock_t *rw)
65 "2: lwarx %0,0,%1 # read_trylock\n\
80 static __inline__ void __raw_read_lock(raw_rwlock_t *rw)
101 static __inline__ void __raw_read_unlock(raw_rwlock_t *rw)
105 __asm__ __volatile__(
106 "eieio # read_unlock\n\
117 static __inline__ int __raw_write_trylock(raw_rwlock_t *rw)
121 __asm__ __volatile__(
122 "2: lwarx %0,0,%1 # write_trylock\n\
131 : "r"(&rw->lock), "r"(-1)
137 static __inline__ void __raw_write_lock(raw_rwlock_t *rw)
141 __asm__ __volatile__(
142 "b 2f # write_lock\n\
154 : "r"(&rw->lock), "r"(-1)
158 static __inline__ void __raw_write_unlock(raw_rwlock_t *rw)
160 __asm__ __volatile__("eieio # write_unlock": : :"memory");
164 #endif /* __ASM_SPINLOCK_H */