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
;
19 #ifdef CONFIG_DEBUG_SPINLOCK
20 #define SPINLOCK_DEBUG_INIT , 0, 0
22 #define SPINLOCK_DEBUG_INIT /* */
25 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 SPINLOCK_DEBUG_INIT }
27 #define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
28 #define spin_is_locked(x) ((x)->lock != 0)
29 #define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x))
30 #define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
32 #ifndef CONFIG_DEBUG_SPINLOCK
34 static inline void _raw_spin_lock(spinlock_t
*lock
)
51 : "r"(&lock
->lock
), "r"(1)
55 static inline void _raw_spin_unlock(spinlock_t
*lock
)
57 __asm__
__volatile__("eieio # spin_unlock": : :"memory");
61 #define _raw_spin_trylock(l) (!test_and_set_bit(0,&(l)->lock))
65 extern void _raw_spin_lock(spinlock_t
*lock
);
66 extern void _raw_spin_unlock(spinlock_t
*lock
);
67 extern int _raw_spin_trylock(spinlock_t
*lock
);
72 * Read-write spinlocks, allowing multiple readers
73 * but only one writer.
75 * NOTE! it is quite common to have readers in interrupts
76 * but no interrupt writers. For those circumstances we
77 * can "mix" irq-safe locks - any writer needs to get a
78 * irq-safe write-lock, but readers can get non-irqsafe
82 volatile unsigned long lock
;
83 #ifdef CONFIG_DEBUG_SPINLOCK
84 volatile unsigned long owner_pc
;
88 #ifdef CONFIG_DEBUG_SPINLOCK
89 #define RWLOCK_DEBUG_INIT , 0
91 #define RWLOCK_DEBUG_INIT /* */
94 #define RW_LOCK_UNLOCKED (rwlock_t) { 0 RWLOCK_DEBUG_INIT }
95 #define rwlock_init(lp) do { *(lp) = RW_LOCK_UNLOCKED; } while(0)
97 #define rwlock_is_locked(x) ((x)->lock != 0)
99 #ifndef CONFIG_DEBUG_SPINLOCK
101 static __inline__
void _raw_read_lock(rwlock_t
*rw
)
105 __asm__
__volatile__(
122 static __inline__
void _raw_read_unlock(rwlock_t
*rw
)
126 __asm__
__volatile__(
127 "eieio # read_unlock\n\
138 static __inline__
int _raw_write_trylock(rwlock_t
*rw
)
142 __asm__
__volatile__(
143 "2: lwarx %0,0,%1 # write_trylock\n\
152 : "r"(&rw
->lock
), "r"(-1)
158 static __inline__
void _raw_write_lock(rwlock_t
*rw
)
162 __asm__
__volatile__(
163 "b 2f # write_lock\n\
175 : "r"(&rw
->lock
), "r"(-1)
179 static __inline__
void _raw_write_unlock(rwlock_t
*rw
)
181 __asm__
__volatile__("eieio # write_unlock": : :"memory");
187 extern void _raw_read_lock(rwlock_t
*rw
);
188 extern void _raw_read_unlock(rwlock_t
*rw
);
189 extern void _raw_write_lock(rwlock_t
*rw
);
190 extern void _raw_write_unlock(rwlock_t
*rw
);
191 extern int _raw_write_trylock(rwlock_t
*rw
);
195 #endif /* __ASM_SPINLOCK_H */
196 #endif /* __KERNEL__ */