1 #ifndef _ALPHA_SPINLOCK_H
2 #define _ALPHA_SPINLOCK_H
4 #include <linux/config.h>
5 #include <asm/system.h>
6 #include <linux/kernel.h>
7 #include <asm/current.h>
11 * Simple spin lock operations. There are two variants, one clears IRQ's
12 * on the local processor, one does not.
14 * We make no fairness assumptions. They have a cost.
18 volatile unsigned int lock /*__attribute__((aligned(32))) */;
19 #if CONFIG_DEBUG_SPINLOCK
23 struct task_struct * task;
24 const char *base_file;
28 #if CONFIG_DEBUG_SPINLOCK
29 #define SPIN_LOCK_UNLOCKED (spinlock_t) {0, -1, 0, 0, 0, 0}
30 #define spin_lock_init(x) \
31 ((x)->lock = 0, (x)->on_cpu = -1, (x)->previous = 0, (x)->task = 0)
33 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
34 #define spin_lock_init(x) ((x)->lock = 0)
37 #define spin_is_locked(x) ((x)->lock != 0)
38 #define spin_unlock_wait(x) ({ do { barrier(); } while ((x)->lock); })
40 #if CONFIG_DEBUG_SPINLOCK
41 extern void spin_unlock(spinlock_t * lock);
42 extern void debug_spin_lock(spinlock_t * lock, const char *, int);
43 extern int debug_spin_trylock(spinlock_t * lock, const char *, int);
45 #define spin_lock(LOCK) debug_spin_lock(LOCK, __BASE_FILE__, __LINE__)
46 #define spin_trylock(LOCK) debug_spin_trylock(LOCK, __BASE_FILE__, __LINE__)
48 #define spin_lock_own(LOCK, LOCATION) \
50 if (!((LOCK)->lock && (LOCK)->on_cpu == smp_processor_id())) \
51 printk("%s: called on %d from %p but lock %s on %d\n", \
52 LOCATION, smp_processor_id(), \
53 __builtin_return_address(0), \
54 (LOCK)->lock ? "taken" : "freed", (LOCK)->on_cpu); \
57 static inline void spin_unlock(spinlock_t * lock)
63 static inline void spin_lock(spinlock_t * lock)
67 /* Use sub-sections to put the actual loop at the end
68 of this object file's text section so as to perfect
82 : "=&r" (tmp), "=m" (lock->lock)
83 : "m"(lock->lock) : "memory");
86 #define spin_trylock(lock) (!test_and_set_bit(0,(lock)))
87 #define spin_lock_own(LOCK, LOCATION) ((void)0)
88 #endif /* CONFIG_DEBUG_SPINLOCK */
90 /***********************************************************/
93 volatile int write_lock:1, read_counter:31;
94 } /*__attribute__((aligned(32)))*/ rwlock_t;
96 #define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0 }
98 #define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
100 #if CONFIG_DEBUG_RWLOCK
101 extern void write_lock(rwlock_t * lock);
102 extern void read_lock(rwlock_t * lock);
104 static inline void write_lock(rwlock_t * lock)
108 __asm__ __volatile__(
120 : "=m" (*(volatile int *)lock), "=&r" (regx)
121 : "0" (*(volatile int *)lock) : "memory");
124 static inline void read_lock(rwlock_t * lock)
128 __asm__ __volatile__(
140 : "=m" (*(volatile int *)lock), "=&r" (regx)
141 : "m" (*(volatile int *)lock) : "memory");
143 #endif /* CONFIG_DEBUG_RWLOCK */
145 static inline void write_unlock(rwlock_t * lock)
148 *(volatile int *)lock = 0;
151 static inline void read_unlock(rwlock_t * lock)
154 __asm__ __volatile__(
163 : "=m" (*(volatile int *)lock), "=&r" (regx)
164 : "m" (*(volatile int *)lock) : "memory");
167 #endif /* _ALPHA_SPINLOCK_H */