1 #ifndef __ASM_SPINLOCK_H
2 #define __ASM_SPINLOCK_H
4 #include <asm/system.h>
7 * Simple spin lock operations.
11 volatile unsigned long lock;
12 #ifdef CONFIG_DEBUG_SPINLOCK
13 volatile unsigned long owner_pc;
14 volatile unsigned long owner_cpu;
17 unsigned int break_lock;
22 #ifdef CONFIG_DEBUG_SPINLOCK
23 #define SPINLOCK_DEBUG_INIT , 0, 0
25 #define SPINLOCK_DEBUG_INIT /* */
28 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 SPINLOCK_DEBUG_INIT }
30 #define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
31 #define spin_is_locked(x) ((x)->lock != 0)
32 #define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x))
33 #define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
35 #ifndef CONFIG_DEBUG_SPINLOCK
37 static inline void _raw_spin_lock(spinlock_t *lock)
54 : "r"(&lock->lock), "r"(1)
58 static inline void _raw_spin_unlock(spinlock_t *lock)
60 __asm__ __volatile__("eieio # spin_unlock": : :"memory");
64 #define _raw_spin_trylock(l) (!test_and_set_bit(0,&(l)->lock))
68 extern void _raw_spin_lock(spinlock_t *lock);
69 extern void _raw_spin_unlock(spinlock_t *lock);
70 extern int _raw_spin_trylock(spinlock_t *lock);
75 * Read-write spinlocks, allowing multiple readers
76 * but only one writer.
78 * NOTE! it is quite common to have readers in interrupts
79 * but no interrupt writers. For those circumstances we
80 * can "mix" irq-safe locks - any writer needs to get a
81 * irq-safe write-lock, but readers can get non-irqsafe
85 volatile signed int lock;
87 unsigned int break_lock;
91 #define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
92 #define rwlock_init(lp) do { *(lp) = RW_LOCK_UNLOCKED; } while(0)
94 #define read_can_lock(rw) ((rw)->lock >= 0)
95 #define write_can_lock(rw) (!(rw)->lock)
97 #ifndef CONFIG_DEBUG_SPINLOCK
99 static __inline__ int _raw_read_trylock(rwlock_t *rw)
103 __asm__ __volatile__(
104 "2: lwarx %0,0,%1 # read_trylock\n\
119 static __inline__ void _raw_read_lock(rwlock_t *rw)
123 __asm__ __volatile__(
140 static __inline__ void _raw_read_unlock(rwlock_t *rw)
144 __asm__ __volatile__(
145 "eieio # read_unlock\n\
156 static __inline__ int _raw_write_trylock(rwlock_t *rw)
160 __asm__ __volatile__(
161 "2: lwarx %0,0,%1 # write_trylock\n\
170 : "r"(&rw->lock), "r"(-1)
176 static __inline__ void _raw_write_lock(rwlock_t *rw)
180 __asm__ __volatile__(
181 "b 2f # write_lock\n\
193 : "r"(&rw->lock), "r"(-1)
197 static __inline__ void _raw_write_unlock(rwlock_t *rw)
199 __asm__ __volatile__("eieio # write_unlock": : :"memory");
205 extern void _raw_read_lock(rwlock_t *rw);
206 extern void _raw_read_unlock(rwlock_t *rw);
207 extern void _raw_write_lock(rwlock_t *rw);
208 extern void _raw_write_unlock(rwlock_t *rw);
209 extern int _raw_read_trylock(rwlock_t *rw);
210 extern int _raw_write_trylock(rwlock_t *rw);
214 #endif /* __ASM_SPINLOCK_H */
215 #endif /* __KERNEL__ */