1 #ifndef __LINUX_RWLOCK_API_SMP_H
2 #define __LINUX_RWLOCK_API_SMP_H
4 #ifndef __LINUX_SPINLOCK_API_SMP_H
5 # error "please don't include this file directly"
9 * include/linux/rwlock_api_smp.h
11 * spinlock API declarations on SMP (and debug)
12 * (implemented in kernel/spinlock.c)
14 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
15 * Released under the General Public License (GPL).
18 void __lockfunc _raw_read_lock(rwlock_t *lock) __acquires(lock);
19 void __lockfunc _raw_write_lock(rwlock_t *lock) __acquires(lock);
20 void __lockfunc _raw_read_lock_bh(rwlock_t *lock) __acquires(lock);
21 void __lockfunc _raw_write_lock_bh(rwlock_t *lock) __acquires(lock);
22 void __lockfunc _raw_read_lock_irq(rwlock_t *lock) __acquires(lock);
23 void __lockfunc _raw_write_lock_irq(rwlock_t *lock) __acquires(lock);
24 unsigned long __lockfunc _raw_read_lock_irqsave(rwlock_t *lock)
26 unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock)
28 int __lockfunc _raw_read_trylock(rwlock_t *lock);
29 int __lockfunc _raw_write_trylock(rwlock_t *lock);
30 void __lockfunc _raw_read_unlock(rwlock_t *lock) __releases(lock);
31 void __lockfunc _raw_write_unlock(rwlock_t *lock) __releases(lock);
32 void __lockfunc _raw_read_unlock_bh(rwlock_t *lock) __releases(lock);
33 void __lockfunc _raw_write_unlock_bh(rwlock_t *lock) __releases(lock);
34 void __lockfunc _raw_read_unlock_irq(rwlock_t *lock) __releases(lock);
35 void __lockfunc _raw_write_unlock_irq(rwlock_t *lock) __releases(lock);
37 _raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
40 _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
43 #ifdef CONFIG_INLINE_READ_LOCK
44 #define _raw_read_lock(lock) __raw_read_lock(lock)
47 #ifdef CONFIG_INLINE_WRITE_LOCK
48 #define _raw_write_lock(lock) __raw_write_lock(lock)
51 #ifdef CONFIG_INLINE_READ_LOCK_BH
52 #define _raw_read_lock_bh(lock) __raw_read_lock_bh(lock)
55 #ifdef CONFIG_INLINE_WRITE_LOCK_BH
56 #define _raw_write_lock_bh(lock) __raw_write_lock_bh(lock)
59 #ifdef CONFIG_INLINE_READ_LOCK_IRQ
60 #define _raw_read_lock_irq(lock) __raw_read_lock_irq(lock)
63 #ifdef CONFIG_INLINE_WRITE_LOCK_IRQ
64 #define _raw_write_lock_irq(lock) __raw_write_lock_irq(lock)
67 #ifdef CONFIG_INLINE_READ_LOCK_IRQSAVE
68 #define _raw_read_lock_irqsave(lock) __raw_read_lock_irqsave(lock)
71 #ifdef CONFIG_INLINE_WRITE_LOCK_IRQSAVE
72 #define _raw_write_lock_irqsave(lock) __raw_write_lock_irqsave(lock)
75 #ifdef CONFIG_INLINE_READ_TRYLOCK
76 #define _raw_read_trylock(lock) __raw_read_trylock(lock)
79 #ifdef CONFIG_INLINE_WRITE_TRYLOCK
80 #define _raw_write_trylock(lock) __raw_write_trylock(lock)
83 #ifdef CONFIG_INLINE_READ_UNLOCK
84 #define _raw_read_unlock(lock) __raw_read_unlock(lock)
87 #ifdef CONFIG_INLINE_WRITE_UNLOCK
88 #define _raw_write_unlock(lock) __raw_write_unlock(lock)
91 #ifdef CONFIG_INLINE_READ_UNLOCK_BH
92 #define _raw_read_unlock_bh(lock) __raw_read_unlock_bh(lock)
95 #ifdef CONFIG_INLINE_WRITE_UNLOCK_BH
96 #define _raw_write_unlock_bh(lock) __raw_write_unlock_bh(lock)
99 #ifdef CONFIG_INLINE_READ_UNLOCK_IRQ
100 #define _raw_read_unlock_irq(lock) __raw_read_unlock_irq(lock)
103 #ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQ
104 #define _raw_write_unlock_irq(lock) __raw_write_unlock_irq(lock)
107 #ifdef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE
108 #define _raw_read_unlock_irqrestore(lock, flags) \
109 __raw_read_unlock_irqrestore(lock, flags)
112 #ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE
113 #define _raw_write_unlock_irqrestore(lock, flags) \
114 __raw_write_unlock_irqrestore(lock, flags)
117 static inline int __raw_read_trylock(rwlock_t *lock)
120 if (do_raw_read_trylock(lock)) {
121 rwlock_acquire_read(&lock->dep_map, 0, 1, _RET_IP_);
128 static inline int __raw_write_trylock(rwlock_t *lock)
131 if (do_raw_write_trylock(lock)) {
132 rwlock_acquire(&lock->dep_map, 0, 1, _RET_IP_);
140 * If lockdep is enabled then we use the non-preemption spin-ops
141 * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are
142 * not re-enabled during lock-acquire (which the preempt-spin-ops do):
144 #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
146 static inline void __raw_read_lock(rwlock_t *lock)
149 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
150 LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
153 static inline unsigned long __raw_read_lock_irqsave(rwlock_t *lock)
157 local_irq_save(flags);
159 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
160 LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
164 static inline void __raw_read_lock_irq(rwlock_t *lock)
168 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
169 LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
172 static inline void __raw_read_lock_bh(rwlock_t *lock)
174 __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
175 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
176 LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
179 static inline unsigned long __raw_write_lock_irqsave(rwlock_t *lock)
183 local_irq_save(flags);
185 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
186 LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
190 static inline void __raw_write_lock_irq(rwlock_t *lock)
194 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
195 LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
198 static inline void __raw_write_lock_bh(rwlock_t *lock)
200 __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
201 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
202 LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
205 static inline void __raw_write_lock(rwlock_t *lock)
208 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
209 LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
212 #endif /* !CONFIG_GENERIC_LOCKBREAK || CONFIG_DEBUG_LOCK_ALLOC */
214 static inline void __raw_write_unlock(rwlock_t *lock)
216 rwlock_release(&lock->dep_map, _RET_IP_);
217 do_raw_write_unlock(lock);
221 static inline void __raw_read_unlock(rwlock_t *lock)
223 rwlock_release(&lock->dep_map, _RET_IP_);
224 do_raw_read_unlock(lock);
229 __raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
231 rwlock_release(&lock->dep_map, _RET_IP_);
232 do_raw_read_unlock(lock);
233 local_irq_restore(flags);
237 static inline void __raw_read_unlock_irq(rwlock_t *lock)
239 rwlock_release(&lock->dep_map, _RET_IP_);
240 do_raw_read_unlock(lock);
245 static inline void __raw_read_unlock_bh(rwlock_t *lock)
247 rwlock_release(&lock->dep_map, _RET_IP_);
248 do_raw_read_unlock(lock);
249 __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
252 static inline void __raw_write_unlock_irqrestore(rwlock_t *lock,
255 rwlock_release(&lock->dep_map, _RET_IP_);
256 do_raw_write_unlock(lock);
257 local_irq_restore(flags);
261 static inline void __raw_write_unlock_irq(rwlock_t *lock)
263 rwlock_release(&lock->dep_map, _RET_IP_);
264 do_raw_write_unlock(lock);
269 static inline void __raw_write_unlock_bh(rwlock_t *lock)
271 rwlock_release(&lock->dep_map, _RET_IP_);
272 do_raw_write_unlock(lock);
273 __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
276 #endif /* __LINUX_RWLOCK_API_SMP_H */