[PATCH] v4l: 888: saa7113 renamed to saa711x
[linux-2.6/verdex.git] / include / asm-parisc / spinlock.h
blob7c3f406a746a4f0984b07efc40e533b24d076561
1 #ifndef __ASM_SPINLOCK_H
2 #define __ASM_SPINLOCK_H
4 #include <asm/system.h>
5 #include <asm/processor.h>
6 #include <asm/spinlock_types.h>
8 static inline int __raw_spin_is_locked(raw_spinlock_t *x)
10 volatile unsigned int *a = __ldcw_align(x);
11 return *a == 0;
14 #define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
15 #define __raw_spin_unlock_wait(x) \
16 do { cpu_relax(); } while (__raw_spin_is_locked(x))
18 static inline void __raw_spin_lock(raw_spinlock_t *x)
20 volatile unsigned int *a;
22 mb();
23 a = __ldcw_align(x);
24 while (__ldcw(a) == 0)
25 while (*a == 0);
26 mb();
29 static inline void __raw_spin_unlock(raw_spinlock_t *x)
31 volatile unsigned int *a;
32 mb();
33 a = __ldcw_align(x);
34 *a = 1;
35 mb();
38 static inline int __raw_spin_trylock(raw_spinlock_t *x)
40 volatile unsigned int *a;
41 int ret;
43 mb();
44 a = __ldcw_align(x);
45 ret = __ldcw(a) != 0;
46 mb();
48 return ret;
52 * Read-write spinlocks, allowing multiple readers
53 * but only one writer.
56 #define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
58 /* read_lock, read_unlock are pretty straightforward. Of course it somehow
59 * sucks we end up saving/restoring flags twice for read_lock_irqsave aso. */
61 static __inline__ void __raw_read_lock(raw_rwlock_t *rw)
63 unsigned long flags;
64 local_irq_save(flags);
65 __raw_spin_lock(&rw->lock);
67 rw->counter++;
69 __raw_spin_unlock(&rw->lock);
70 local_irq_restore(flags);
73 static __inline__ void __raw_read_unlock(raw_rwlock_t *rw)
75 unsigned long flags;
76 local_irq_save(flags);
77 __raw_spin_lock(&rw->lock);
79 rw->counter--;
81 __raw_spin_unlock(&rw->lock);
82 local_irq_restore(flags);
85 /* write_lock is less trivial. We optimistically grab the lock and check
86 * if we surprised any readers. If so we release the lock and wait till
87 * they're all gone before trying again
89 * Also note that we don't use the _irqsave / _irqrestore suffixes here.
90 * If we're called with interrupts enabled and we've got readers (or other
91 * writers) in interrupt handlers someone fucked up and we'd dead-lock
92 * sooner or later anyway. prumpf */
94 static __inline__ void __raw_write_lock(raw_rwlock_t *rw)
96 retry:
97 __raw_spin_lock(&rw->lock);
99 if(rw->counter != 0) {
100 /* this basically never happens */
101 __raw_spin_unlock(&rw->lock);
103 while (rw->counter != 0)
104 cpu_relax();
106 goto retry;
109 /* got it. now leave without unlocking */
110 rw->counter = -1; /* remember we are locked */
113 /* write_unlock is absolutely trivial - we don't have to wait for anything */
115 static __inline__ void __raw_write_unlock(raw_rwlock_t *rw)
117 rw->counter = 0;
118 __raw_spin_unlock(&rw->lock);
121 static __inline__ int __raw_write_trylock(raw_rwlock_t *rw)
123 __raw_spin_lock(&rw->lock);
124 if (rw->counter != 0) {
125 /* this basically never happens */
126 __raw_spin_unlock(&rw->lock);
128 return 0;
131 /* got it. now leave without unlocking */
132 rw->counter = -1; /* remember we are locked */
133 return 1;
136 static __inline__ int __raw_is_read_locked(raw_rwlock_t *rw)
138 return rw->counter > 0;
141 static __inline__ int __raw_is_write_locked(raw_rwlock_t *rw)
143 return rw->counter < 0;
146 #endif /* __ASM_SPINLOCK_H */