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
);
14 #define __raw_spin_lock(lock) __raw_spin_lock_flags(lock, 0)
15 #define __raw_spin_unlock_wait(x) \
16 do { cpu_relax(); } while (__raw_spin_is_locked(x))
18 static inline void __raw_spin_lock_flags(raw_spinlock_t
*x
,
21 volatile unsigned int *a
;
25 while (__ldcw(a
) == 0)
27 if (flags
& PSW_SM_I
) {
36 static inline void __raw_spin_unlock(raw_spinlock_t
*x
)
38 volatile unsigned int *a
;
45 static inline int __raw_spin_trylock(raw_spinlock_t
*x
)
47 volatile unsigned int *a
;
59 * Read-write spinlocks, allowing multiple readers
60 * but only one writer.
63 #define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
65 /* read_lock, read_unlock are pretty straightforward. Of course it somehow
66 * sucks we end up saving/restoring flags twice for read_lock_irqsave aso. */
68 static __inline__
void __raw_read_lock(raw_rwlock_t
*rw
)
70 __raw_spin_lock(&rw
->lock
);
74 __raw_spin_unlock(&rw
->lock
);
77 static __inline__
void __raw_read_unlock(raw_rwlock_t
*rw
)
79 __raw_spin_lock(&rw
->lock
);
83 __raw_spin_unlock(&rw
->lock
);
86 /* write_lock is less trivial. We optimistically grab the lock and check
87 * if we surprised any readers. If so we release the lock and wait till
88 * they're all gone before trying again
90 * Also note that we don't use the _irqsave / _irqrestore suffixes here.
91 * If we're called with interrupts enabled and we've got readers (or other
92 * writers) in interrupt handlers someone fucked up and we'd dead-lock
93 * sooner or later anyway. prumpf */
95 static __inline__
void __raw_write_lock(raw_rwlock_t
*rw
)
98 __raw_spin_lock(&rw
->lock
);
100 if(rw
->counter
!= 0) {
101 /* this basically never happens */
102 __raw_spin_unlock(&rw
->lock
);
104 while (rw
->counter
!= 0)
110 /* got it. now leave without unlocking */
111 rw
->counter
= -1; /* remember we are locked */
114 /* write_unlock is absolutely trivial - we don't have to wait for anything */
116 static __inline__
void __raw_write_unlock(raw_rwlock_t
*rw
)
119 __raw_spin_unlock(&rw
->lock
);
122 static __inline__
int __raw_write_trylock(raw_rwlock_t
*rw
)
124 __raw_spin_lock(&rw
->lock
);
125 if (rw
->counter
!= 0) {
126 /* this basically never happens */
127 __raw_spin_unlock(&rw
->lock
);
132 /* got it. now leave without unlocking */
133 rw
->counter
= -1; /* remember we are locked */
138 * read_can_lock - would read_trylock() succeed?
139 * @lock: the rwlock in question.
141 static __inline__
int __raw_read_can_lock(raw_rwlock_t
*rw
)
143 return rw
->counter
>= 0;
147 * write_can_lock - would write_trylock() succeed?
148 * @lock: the rwlock in question.
150 static __inline__
int __raw_write_can_lock(raw_rwlock_t
*rw
)
155 #endif /* __ASM_SPINLOCK_H */