aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-sparc64/spinlock.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-sparc64/spinlock.h')
-rw-r--r--include/asm-sparc64/spinlock.h48
1 files changed, 31 insertions, 17 deletions
diff --git a/include/asm-sparc64/spinlock.h b/include/asm-sparc64/spinlock.h
index 11efa474865b..d1f91a4f24ae 100644
--- a/include/asm-sparc64/spinlock.h
+++ b/include/asm-sparc64/spinlock.h
@@ -31,15 +31,20 @@
31 31
32#ifndef CONFIG_DEBUG_SPINLOCK 32#ifndef CONFIG_DEBUG_SPINLOCK
33 33
34typedef unsigned char spinlock_t; 34typedef struct {
35#define SPIN_LOCK_UNLOCKED 0 35 volatile unsigned char lock;
36#ifdef CONFIG_PREEMPT
37 unsigned int break_lock;
38#endif
39} spinlock_t;
40#define SPIN_LOCK_UNLOCKED (spinlock_t) {0,}
36 41
37#define spin_lock_init(lock) (*((unsigned char *)(lock)) = 0) 42#define spin_lock_init(lp) do { *(lp)= SPIN_LOCK_UNLOCKED; } while(0)
38#define spin_is_locked(lock) (*((volatile unsigned char *)(lock)) != 0) 43#define spin_is_locked(lp) ((lp)->lock != 0)
39 44
40#define spin_unlock_wait(lock) \ 45#define spin_unlock_wait(lp) \
41do { membar("#LoadLoad"); \ 46do { membar("#LoadLoad"); \
42} while(*((volatile unsigned char *)lock)) 47} while(lp->lock)
43 48
44static inline void _raw_spin_lock(spinlock_t *lock) 49static inline void _raw_spin_lock(spinlock_t *lock)
45{ 50{
@@ -109,20 +114,19 @@ static inline void _raw_spin_lock_flags(spinlock_t *lock, unsigned long flags)
109#else /* !(CONFIG_DEBUG_SPINLOCK) */ 114#else /* !(CONFIG_DEBUG_SPINLOCK) */
110 115
111typedef struct { 116typedef struct {
112 unsigned char lock; 117 volatile unsigned char lock;
113 unsigned int owner_pc, owner_cpu; 118 unsigned int owner_pc, owner_cpu;
119#ifdef CONFIG_PREEMPT
120 unsigned int break_lock;
121#endif
114} spinlock_t; 122} spinlock_t;
115#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0, 0, 0xff } 123#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0, 0, 0xff }
116#define spin_lock_init(__lock) \ 124#define spin_lock_init(lp) do { *(lp)= SPIN_LOCK_UNLOCKED; } while(0)
117do { (__lock)->lock = 0; \ 125#define spin_is_locked(__lock) ((__lock)->lock != 0)
118 (__lock)->owner_pc = 0; \
119 (__lock)->owner_cpu = 0xff; \
120} while(0)
121#define spin_is_locked(__lock) (*((volatile unsigned char *)(&((__lock)->lock))) != 0)
122#define spin_unlock_wait(__lock) \ 126#define spin_unlock_wait(__lock) \
123do { \ 127do { \
124 membar("#LoadLoad"); \ 128 membar("#LoadLoad"); \
125} while(*((volatile unsigned char *)(&((__lock)->lock)))) 129} while((__lock)->lock)
126 130
127extern void _do_spin_lock (spinlock_t *lock, char *str); 131extern void _do_spin_lock (spinlock_t *lock, char *str);
128extern void _do_spin_unlock (spinlock_t *lock); 132extern void _do_spin_unlock (spinlock_t *lock);
@@ -139,8 +143,13 @@ extern int _do_spin_trylock (spinlock_t *lock);
139 143
140#ifndef CONFIG_DEBUG_SPINLOCK 144#ifndef CONFIG_DEBUG_SPINLOCK
141 145
142typedef unsigned int rwlock_t; 146typedef struct {
143#define RW_LOCK_UNLOCKED 0 147 volatile unsigned int lock;
148#ifdef CONFIG_PREEMPT
149 unsigned int break_lock;
150#endif
151} rwlock_t;
152#define RW_LOCK_UNLOCKED {0,}
144#define rwlock_init(lp) do { *(lp) = RW_LOCK_UNLOCKED; } while(0) 153#define rwlock_init(lp) do { *(lp) = RW_LOCK_UNLOCKED; } while(0)
145 154
146static void inline __read_lock(rwlock_t *lock) 155static void inline __read_lock(rwlock_t *lock)
@@ -251,9 +260,12 @@ static int inline __write_trylock(rwlock_t *lock)
251#else /* !(CONFIG_DEBUG_SPINLOCK) */ 260#else /* !(CONFIG_DEBUG_SPINLOCK) */
252 261
253typedef struct { 262typedef struct {
254 unsigned long lock; 263 volatile unsigned long lock;
255 unsigned int writer_pc, writer_cpu; 264 unsigned int writer_pc, writer_cpu;
256 unsigned int reader_pc[NR_CPUS]; 265 unsigned int reader_pc[NR_CPUS];
266#ifdef CONFIG_PREEMPT
267 unsigned int break_lock;
268#endif
257} rwlock_t; 269} rwlock_t;
258#define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0, 0xff, { } } 270#define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0, 0xff, { } }
259#define rwlock_init(lp) do { *(lp) = RW_LOCK_UNLOCKED; } while(0) 271#define rwlock_init(lp) do { *(lp) = RW_LOCK_UNLOCKED; } while(0)
@@ -304,6 +316,8 @@ do { unsigned long flags; \
304#endif /* CONFIG_DEBUG_SPINLOCK */ 316#endif /* CONFIG_DEBUG_SPINLOCK */
305 317
306#define _raw_read_trylock(lock) generic_raw_read_trylock(lock) 318#define _raw_read_trylock(lock) generic_raw_read_trylock(lock)
319#define read_can_lock(rw) (!((rw)->lock & 0x80000000UL))
320#define write_can_lock(rw) (!(rw)->lock)
307 321
308#endif /* !(__ASSEMBLY__) */ 322#endif /* !(__ASSEMBLY__) */
309 323