blob: 9c9f0495d37c0d41643a24c25e8447e4ee90d576 [file] [log] [blame]
Thomas Gleixner6b6b4792009-11-16 18:48:37 +01001#ifndef __LINUX_RWLOCK_API_SMP_H
2#define __LINUX_RWLOCK_API_SMP_H
3
4#ifndef __LINUX_SPINLOCK_API_SMP_H
5# error "please don't include this file directly"
6#endif
7
8/*
9 * include/linux/rwlock_api_smp.h
10 *
11 * spinlock API declarations on SMP (and debug)
12 * (implemented in kernel/spinlock.c)
13 *
14 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
15 * Released under the General Public License (GPL).
16 */
17
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010018void __lockfunc _raw_read_lock(rwlock_t *lock) __acquires(lock);
19void __lockfunc _raw_write_lock(rwlock_t *lock) __acquires(lock);
20void __lockfunc _raw_read_lock_bh(rwlock_t *lock) __acquires(lock);
21void __lockfunc _raw_write_lock_bh(rwlock_t *lock) __acquires(lock);
22void __lockfunc _raw_read_lock_irq(rwlock_t *lock) __acquires(lock);
23void __lockfunc _raw_write_lock_irq(rwlock_t *lock) __acquires(lock);
24unsigned long __lockfunc _raw_read_lock_irqsave(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010025 __acquires(lock);
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010026unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010027 __acquires(lock);
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010028int __lockfunc _raw_read_trylock(rwlock_t *lock);
29int __lockfunc _raw_write_trylock(rwlock_t *lock);
30void __lockfunc _raw_read_unlock(rwlock_t *lock) __releases(lock);
31void __lockfunc _raw_write_unlock(rwlock_t *lock) __releases(lock);
32void __lockfunc _raw_read_unlock_bh(rwlock_t *lock) __releases(lock);
33void __lockfunc _raw_write_unlock_bh(rwlock_t *lock) __releases(lock);
34void __lockfunc _raw_read_unlock_irq(rwlock_t *lock) __releases(lock);
35void __lockfunc _raw_write_unlock_irq(rwlock_t *lock) __releases(lock);
36void __lockfunc
37_raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010038 __releases(lock);
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010039void __lockfunc
40_raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010041 __releases(lock);
42
43#ifdef CONFIG_INLINE_READ_LOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010044#define _raw_read_lock(lock) __raw_read_lock(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010045#endif
46
47#ifdef CONFIG_INLINE_WRITE_LOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010048#define _raw_write_lock(lock) __raw_write_lock(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010049#endif
50
51#ifdef CONFIG_INLINE_READ_LOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010052#define _raw_read_lock_bh(lock) __raw_read_lock_bh(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010053#endif
54
55#ifdef CONFIG_INLINE_WRITE_LOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010056#define _raw_write_lock_bh(lock) __raw_write_lock_bh(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010057#endif
58
59#ifdef CONFIG_INLINE_READ_LOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010060#define _raw_read_lock_irq(lock) __raw_read_lock_irq(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010061#endif
62
63#ifdef CONFIG_INLINE_WRITE_LOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010064#define _raw_write_lock_irq(lock) __raw_write_lock_irq(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010065#endif
66
67#ifdef CONFIG_INLINE_READ_LOCK_IRQSAVE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010068#define _raw_read_lock_irqsave(lock) __raw_read_lock_irqsave(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010069#endif
70
71#ifdef CONFIG_INLINE_WRITE_LOCK_IRQSAVE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010072#define _raw_write_lock_irqsave(lock) __raw_write_lock_irqsave(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010073#endif
74
75#ifdef CONFIG_INLINE_READ_TRYLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010076#define _raw_read_trylock(lock) __raw_read_trylock(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010077#endif
78
79#ifdef CONFIG_INLINE_WRITE_TRYLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010080#define _raw_write_trylock(lock) __raw_write_trylock(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010081#endif
82
83#ifdef CONFIG_INLINE_READ_UNLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010084#define _raw_read_unlock(lock) __raw_read_unlock(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010085#endif
86
87#ifdef CONFIG_INLINE_WRITE_UNLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010088#define _raw_write_unlock(lock) __raw_write_unlock(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010089#endif
90
91#ifdef CONFIG_INLINE_READ_UNLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010092#define _raw_read_unlock_bh(lock) __raw_read_unlock_bh(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010093#endif
94
95#ifdef CONFIG_INLINE_WRITE_UNLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010096#define _raw_write_unlock_bh(lock) __raw_write_unlock_bh(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010097#endif
98
99#ifdef CONFIG_INLINE_READ_UNLOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100100#define _raw_read_unlock_irq(lock) __raw_read_unlock_irq(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100101#endif
102
103#ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100104#define _raw_write_unlock_irq(lock) __raw_write_unlock_irq(lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100105#endif
106
107#ifdef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100108#define _raw_read_unlock_irqrestore(lock, flags) \
109 __raw_read_unlock_irqrestore(lock, flags)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100110#endif
111
112#ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100113#define _raw_write_unlock_irqrestore(lock, flags) \
114 __raw_write_unlock_irqrestore(lock, flags)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100115#endif
116
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100117static inline int __raw_read_trylock(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100118{
119 preempt_disable();
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100120 if (do_raw_read_trylock(lock)) {
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100121 rwlock_acquire_read(&lock->dep_map, 0, 1, _RET_IP_);
122 return 1;
123 }
124 preempt_enable();
125 return 0;
126}
127
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100128static inline int __raw_write_trylock(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100129{
130 preempt_disable();
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100131 if (do_raw_write_trylock(lock)) {
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100132 rwlock_acquire(&lock->dep_map, 0, 1, _RET_IP_);
133 return 1;
134 }
135 preempt_enable();
136 return 0;
137}
138
139/*
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):
143 */
144#if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
145
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100146static inline void __raw_read_lock(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100147{
148 preempt_disable();
149 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100150 LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100151}
152
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100153static inline unsigned long __raw_read_lock_irqsave(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100154{
155 unsigned long flags;
156
157 local_irq_save(flags);
158 preempt_disable();
159 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100160 LOCK_CONTENDED_FLAGS(lock, do_raw_read_trylock, do_raw_read_lock,
161 do_raw_read_lock_flags, &flags);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100162 return flags;
163}
164
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100165static inline void __raw_read_lock_irq(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100166{
167 local_irq_disable();
168 preempt_disable();
169 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100170 LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100171}
172
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100173static inline void __raw_read_lock_bh(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100174{
175 local_bh_disable();
176 preempt_disable();
177 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100178 LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100179}
180
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100181static inline unsigned long __raw_write_lock_irqsave(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100182{
183 unsigned long flags;
184
185 local_irq_save(flags);
186 preempt_disable();
187 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100188 LOCK_CONTENDED_FLAGS(lock, do_raw_write_trylock, do_raw_write_lock,
189 do_raw_write_lock_flags, &flags);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100190 return flags;
191}
192
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100193static inline void __raw_write_lock_irq(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100194{
195 local_irq_disable();
196 preempt_disable();
197 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100198 LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100199}
200
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100201static inline void __raw_write_lock_bh(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100202{
203 local_bh_disable();
204 preempt_disable();
205 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100206 LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100207}
208
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100209static inline void __raw_write_lock(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100210{
211 preempt_disable();
212 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100213 LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100214}
215
216#endif /* CONFIG_PREEMPT */
217
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100218static inline void __raw_write_unlock(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100219{
220 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100221 do_raw_write_unlock(lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100222 preempt_enable();
223}
224
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100225static inline void __raw_read_unlock(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100226{
227 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100228 do_raw_read_unlock(lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100229 preempt_enable();
230}
231
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100232static inline void
233__raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100234{
235 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100236 do_raw_read_unlock(lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100237 local_irq_restore(flags);
238 preempt_enable();
239}
240
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100241static inline void __raw_read_unlock_irq(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100242{
243 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100244 do_raw_read_unlock(lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100245 local_irq_enable();
246 preempt_enable();
247}
248
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100249static inline void __raw_read_unlock_bh(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100250{
251 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100252 do_raw_read_unlock(lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100253 preempt_enable_no_resched();
254 local_bh_enable_ip((unsigned long)__builtin_return_address(0));
255}
256
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100257static inline void __raw_write_unlock_irqrestore(rwlock_t *lock,
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100258 unsigned long flags)
259{
260 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100261 do_raw_write_unlock(lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100262 local_irq_restore(flags);
263 preempt_enable();
264}
265
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100266static inline void __raw_write_unlock_irq(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100267{
268 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100269 do_raw_write_unlock(lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100270 local_irq_enable();
271 preempt_enable();
272}
273
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100274static inline void __raw_write_unlock_bh(rwlock_t *lock)
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100275{
276 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100277 do_raw_write_unlock(lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100278 preempt_enable_no_resched();
279 local_bh_enable_ip((unsigned long)__builtin_return_address(0));
280}
281
282#endif /* __LINUX_RWLOCK_API_SMP_H */