1 #ifndef __LINUX_RWLOCK_API_SMP_H
2 #define __LINUX_RWLOCK_API_SMP_H
4 #ifndef __LINUX_SPINLOCK_API_SMP_H
5 # error "Please do not 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_write_lock_nested(rwlock_t
*lock
, int subclass
) __acquires(lock
);
21 void __lockfunc
_raw_read_lock_bh(rwlock_t
*lock
) __acquires(lock
);
22 void __lockfunc
_raw_write_lock_bh(rwlock_t
*lock
) __acquires(lock
);
23 void __lockfunc
_raw_read_lock_irq(rwlock_t
*lock
) __acquires(lock
);
24 void __lockfunc
_raw_write_lock_irq(rwlock_t
*lock
) __acquires(lock
);
25 unsigned long __lockfunc
_raw_read_lock_irqsave(rwlock_t
*lock
)
27 unsigned long __lockfunc
_raw_write_lock_irqsave(rwlock_t
*lock
)
29 int __lockfunc
_raw_read_trylock(rwlock_t
*lock
);
30 int __lockfunc
_raw_write_trylock(rwlock_t
*lock
);
31 void __lockfunc
_raw_read_unlock(rwlock_t
*lock
) __releases(lock
);
32 void __lockfunc
_raw_write_unlock(rwlock_t
*lock
) __releases(lock
);
33 void __lockfunc
_raw_read_unlock_bh(rwlock_t
*lock
) __releases(lock
);
34 void __lockfunc
_raw_write_unlock_bh(rwlock_t
*lock
) __releases(lock
);
35 void __lockfunc
_raw_read_unlock_irq(rwlock_t
*lock
) __releases(lock
);
36 void __lockfunc
_raw_write_unlock_irq(rwlock_t
*lock
) __releases(lock
);
38 _raw_read_unlock_irqrestore(rwlock_t
*lock
, unsigned long flags
)
41 _raw_write_unlock_irqrestore(rwlock_t
*lock
, unsigned long flags
)
44 #ifdef CONFIG_INLINE_READ_LOCK
45 #define _raw_read_lock(lock) __raw_read_lock(lock)
48 #ifdef CONFIG_INLINE_WRITE_LOCK
49 #define _raw_write_lock(lock) __raw_write_lock(lock)
52 #ifdef CONFIG_INLINE_READ_LOCK_BH
53 #define _raw_read_lock_bh(lock) __raw_read_lock_bh(lock)
56 #ifdef CONFIG_INLINE_WRITE_LOCK_BH
57 #define _raw_write_lock_bh(lock) __raw_write_lock_bh(lock)
60 #ifdef CONFIG_INLINE_READ_LOCK_IRQ
61 #define _raw_read_lock_irq(lock) __raw_read_lock_irq(lock)
64 #ifdef CONFIG_INLINE_WRITE_LOCK_IRQ
65 #define _raw_write_lock_irq(lock) __raw_write_lock_irq(lock)
68 #ifdef CONFIG_INLINE_READ_LOCK_IRQSAVE
69 #define _raw_read_lock_irqsave(lock) __raw_read_lock_irqsave(lock)
72 #ifdef CONFIG_INLINE_WRITE_LOCK_IRQSAVE
73 #define _raw_write_lock_irqsave(lock) __raw_write_lock_irqsave(lock)
76 #ifdef CONFIG_INLINE_READ_TRYLOCK
77 #define _raw_read_trylock(lock) __raw_read_trylock(lock)
80 #ifdef CONFIG_INLINE_WRITE_TRYLOCK
81 #define _raw_write_trylock(lock) __raw_write_trylock(lock)
84 #ifdef CONFIG_INLINE_READ_UNLOCK
85 #define _raw_read_unlock(lock) __raw_read_unlock(lock)
88 #ifdef CONFIG_INLINE_WRITE_UNLOCK
89 #define _raw_write_unlock(lock) __raw_write_unlock(lock)
92 #ifdef CONFIG_INLINE_READ_UNLOCK_BH
93 #define _raw_read_unlock_bh(lock) __raw_read_unlock_bh(lock)
96 #ifdef CONFIG_INLINE_WRITE_UNLOCK_BH
97 #define _raw_write_unlock_bh(lock) __raw_write_unlock_bh(lock)
100 #ifdef CONFIG_INLINE_READ_UNLOCK_IRQ
101 #define _raw_read_unlock_irq(lock) __raw_read_unlock_irq(lock)
104 #ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQ
105 #define _raw_write_unlock_irq(lock) __raw_write_unlock_irq(lock)
108 #ifdef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE
109 #define _raw_read_unlock_irqrestore(lock, flags) \
110 __raw_read_unlock_irqrestore(lock, flags)
113 #ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE
114 #define _raw_write_unlock_irqrestore(lock, flags) \
115 __raw_write_unlock_irqrestore(lock, flags)
118 static inline int __raw_read_trylock(rwlock_t
*lock
)
121 if (do_raw_read_trylock(lock
)) {
122 rwlock_acquire_read(&lock
->dep_map
, 0, 1, _RET_IP_
);
129 static inline int __raw_write_trylock(rwlock_t
*lock
)
132 if (do_raw_write_trylock(lock
)) {
133 rwlock_acquire(&lock
->dep_map
, 0, 1, _RET_IP_
);
141 * If lockdep is enabled then we use the non-preemption spin-ops
142 * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are
143 * not re-enabled during lock-acquire (which the preempt-spin-ops do):
145 #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
147 static inline void __raw_read_lock(rwlock_t
*lock
)
150 rwlock_acquire_read(&lock
->dep_map
, 0, 0, _RET_IP_
);
151 LOCK_CONTENDED(lock
, do_raw_read_trylock
, do_raw_read_lock
);
154 static inline unsigned long __raw_read_lock_irqsave(rwlock_t
*lock
)
158 local_irq_save(flags
);
160 rwlock_acquire_read(&lock
->dep_map
, 0, 0, _RET_IP_
);
161 LOCK_CONTENDED(lock
, do_raw_read_trylock
, do_raw_read_lock
);
165 static inline void __raw_read_lock_irq(rwlock_t
*lock
)
169 rwlock_acquire_read(&lock
->dep_map
, 0, 0, _RET_IP_
);
170 LOCK_CONTENDED(lock
, do_raw_read_trylock
, do_raw_read_lock
);
173 static inline void __raw_read_lock_bh(rwlock_t
*lock
)
175 __local_bh_disable_ip(_RET_IP_
, SOFTIRQ_LOCK_OFFSET
);
176 rwlock_acquire_read(&lock
->dep_map
, 0, 0, _RET_IP_
);
177 LOCK_CONTENDED(lock
, do_raw_read_trylock
, do_raw_read_lock
);
180 static inline unsigned long __raw_write_lock_irqsave(rwlock_t
*lock
)
184 local_irq_save(flags
);
186 rwlock_acquire(&lock
->dep_map
, 0, 0, _RET_IP_
);
187 LOCK_CONTENDED(lock
, do_raw_write_trylock
, do_raw_write_lock
);
191 static inline void __raw_write_lock_irq(rwlock_t
*lock
)
195 rwlock_acquire(&lock
->dep_map
, 0, 0, _RET_IP_
);
196 LOCK_CONTENDED(lock
, do_raw_write_trylock
, do_raw_write_lock
);
199 static inline void __raw_write_lock_bh(rwlock_t
*lock
)
201 __local_bh_disable_ip(_RET_IP_
, SOFTIRQ_LOCK_OFFSET
);
202 rwlock_acquire(&lock
->dep_map
, 0, 0, _RET_IP_
);
203 LOCK_CONTENDED(lock
, do_raw_write_trylock
, do_raw_write_lock
);
206 static inline void __raw_write_lock(rwlock_t
*lock
)
209 rwlock_acquire(&lock
->dep_map
, 0, 0, _RET_IP_
);
210 LOCK_CONTENDED(lock
, do_raw_write_trylock
, do_raw_write_lock
);
213 static inline void __raw_write_lock_nested(rwlock_t
*lock
, int subclass
)
216 rwlock_acquire(&lock
->dep_map
, subclass
, 0, _RET_IP_
);
217 LOCK_CONTENDED(lock
, do_raw_write_trylock
, do_raw_write_lock
);
220 #endif /* !CONFIG_GENERIC_LOCKBREAK || CONFIG_DEBUG_LOCK_ALLOC */
222 static inline void __raw_write_unlock(rwlock_t
*lock
)
224 rwlock_release(&lock
->dep_map
, _RET_IP_
);
225 do_raw_write_unlock(lock
);
229 static inline void __raw_read_unlock(rwlock_t
*lock
)
231 rwlock_release(&lock
->dep_map
, _RET_IP_
);
232 do_raw_read_unlock(lock
);
237 __raw_read_unlock_irqrestore(rwlock_t
*lock
, unsigned long flags
)
239 rwlock_release(&lock
->dep_map
, _RET_IP_
);
240 do_raw_read_unlock(lock
);
241 local_irq_restore(flags
);
245 static inline void __raw_read_unlock_irq(rwlock_t
*lock
)
247 rwlock_release(&lock
->dep_map
, _RET_IP_
);
248 do_raw_read_unlock(lock
);
253 static inline void __raw_read_unlock_bh(rwlock_t
*lock
)
255 rwlock_release(&lock
->dep_map
, _RET_IP_
);
256 do_raw_read_unlock(lock
);
257 __local_bh_enable_ip(_RET_IP_
, SOFTIRQ_LOCK_OFFSET
);
260 static inline void __raw_write_unlock_irqrestore(rwlock_t
*lock
,
263 rwlock_release(&lock
->dep_map
, _RET_IP_
);
264 do_raw_write_unlock(lock
);
265 local_irq_restore(flags
);
269 static inline void __raw_write_unlock_irq(rwlock_t
*lock
)
271 rwlock_release(&lock
->dep_map
, _RET_IP_
);
272 do_raw_write_unlock(lock
);
277 static inline void __raw_write_unlock_bh(rwlock_t
*lock
)
279 rwlock_release(&lock
->dep_map
, _RET_IP_
);
280 do_raw_write_unlock(lock
);
281 __local_bh_enable_ip(_RET_IP_
, SOFTIRQ_LOCK_OFFSET
);
284 #endif /* __LINUX_RWLOCK_API_SMP_H */