17 #include <linux/linkage.h>
22 #include <linux/export.h>
29 #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
35 #define raw_read_can_lock(l) read_can_lock(l)
36 #define raw_write_can_lock(l) write_can_lock(l)
46 #define BUILD_LOCK_OPS(op, locktype) \
47 void __lockfunc __raw_##op##_lock(locktype##_t *lock) \
51 if (likely(do_raw_##op##_trylock(lock))) \
55 if (!(lock)->break_lock) \
56 (lock)->break_lock = 1; \
57 while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\
58 arch_##op##_relax(&lock->raw_lock); \
60 (lock)->break_lock = 0; \
63 unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock) \
65 unsigned long flags; \
69 local_irq_save(flags); \
70 if (likely(do_raw_##op##_trylock(lock))) \
72 local_irq_restore(flags); \
75 if (!(lock)->break_lock) \
76 (lock)->break_lock = 1; \
77 while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\
78 arch_##op##_relax(&lock->raw_lock); \
80 (lock)->break_lock = 0; \
84 void __lockfunc __raw_##op##_lock_irq(locktype##_t *lock) \
86 _raw_##op##_lock_irqsave(lock); \
89 void __lockfunc __raw_##op##_lock_bh(locktype##_t *lock) \
91 unsigned long flags; \
98 flags = _raw_##op##_lock_irqsave(lock); \
100 local_irq_restore(flags); \
113 BUILD_LOCK_OPS(
read, rwlock);
114 BUILD_LOCK_OPS(
write, rwlock);
118 #ifndef CONFIG_INLINE_SPIN_TRYLOCK
121 return __raw_spin_trylock(lock);
126 #ifndef CONFIG_INLINE_SPIN_TRYLOCK_BH
129 return __raw_spin_trylock_bh(lock);
134 #ifndef CONFIG_INLINE_SPIN_LOCK
137 __raw_spin_lock(lock);
142 #ifndef CONFIG_INLINE_SPIN_LOCK_IRQSAVE
145 return __raw_spin_lock_irqsave(lock);
150 #ifndef CONFIG_INLINE_SPIN_LOCK_IRQ
153 __raw_spin_lock_irq(lock);
158 #ifndef CONFIG_INLINE_SPIN_LOCK_BH
161 __raw_spin_lock_bh(lock);
166 #ifdef CONFIG_UNINLINE_SPIN_UNLOCK
169 __raw_spin_unlock(lock);
174 #ifndef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE
177 __raw_spin_unlock_irqrestore(lock, flags);
182 #ifndef CONFIG_INLINE_SPIN_UNLOCK_IRQ
185 __raw_spin_unlock_irq(lock);
190 #ifndef CONFIG_INLINE_SPIN_UNLOCK_BH
193 __raw_spin_unlock_bh(lock);
198 #ifndef CONFIG_INLINE_READ_TRYLOCK
201 return __raw_read_trylock(lock);
206 #ifndef CONFIG_INLINE_READ_LOCK
209 __raw_read_lock(lock);
214 #ifndef CONFIG_INLINE_READ_LOCK_IRQSAVE
217 return __raw_read_lock_irqsave(lock);
222 #ifndef CONFIG_INLINE_READ_LOCK_IRQ
225 __raw_read_lock_irq(lock);
230 #ifndef CONFIG_INLINE_READ_LOCK_BH
233 __raw_read_lock_bh(lock);
238 #ifndef CONFIG_INLINE_READ_UNLOCK
241 __raw_read_unlock(lock);
246 #ifndef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE
249 __raw_read_unlock_irqrestore(lock, flags);
254 #ifndef CONFIG_INLINE_READ_UNLOCK_IRQ
257 __raw_read_unlock_irq(lock);
262 #ifndef CONFIG_INLINE_READ_UNLOCK_BH
265 __raw_read_unlock_bh(lock);
270 #ifndef CONFIG_INLINE_WRITE_TRYLOCK
273 return __raw_write_trylock(lock);
278 #ifndef CONFIG_INLINE_WRITE_LOCK
281 __raw_write_lock(lock);
286 #ifndef CONFIG_INLINE_WRITE_LOCK_IRQSAVE
289 return __raw_write_lock_irqsave(lock);
294 #ifndef CONFIG_INLINE_WRITE_LOCK_IRQ
297 __raw_write_lock_irq(lock);
302 #ifndef CONFIG_INLINE_WRITE_LOCK_BH
305 __raw_write_lock_bh(lock);
310 #ifndef CONFIG_INLINE_WRITE_UNLOCK
313 __raw_write_unlock(lock);
318 #ifndef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE
321 __raw_write_unlock_irqrestore(lock, flags);
326 #ifndef CONFIG_INLINE_WRITE_UNLOCK_IRQ
329 __raw_write_unlock_irq(lock);
334 #ifndef CONFIG_INLINE_WRITE_UNLOCK_BH
337 __raw_write_unlock_bh(lock);
342 #ifdef CONFIG_DEBUG_LOCK_ALLOC
361 do_raw_spin_lock_flags, &flags);
367 struct lockdep_map *nest_lock)
370 spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock,
_RET_IP_);
380 extern char __lock_text_start[], __lock_text_end[];
382 return addr >= (
unsigned long)__lock_text_start
383 && addr < (
unsigned long)__lock_text_end;