Blame view

include/linux/rwlock_api_smp.h 7.68 KB
6b6b4792f   Thomas Gleixner   locking: Separate...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #ifndef __LINUX_RWLOCK_API_SMP_H
  #define __LINUX_RWLOCK_API_SMP_H
  
  #ifndef __LINUX_SPINLOCK_API_SMP_H
  # error "please don't include this file directly"
  #endif
  
  /*
   * include/linux/rwlock_api_smp.h
   *
   * spinlock API declarations on SMP (and debug)
   * (implemented in kernel/spinlock.c)
   *
   * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
   * Released under the General Public License (GPL).
   */
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
17
18
19
20
21
22
23
  void __lockfunc _raw_read_lock(rwlock_t *lock)		__acquires(lock);
  void __lockfunc _raw_write_lock(rwlock_t *lock)		__acquires(lock);
  void __lockfunc _raw_read_lock_bh(rwlock_t *lock)	__acquires(lock);
  void __lockfunc _raw_write_lock_bh(rwlock_t *lock)	__acquires(lock);
  void __lockfunc _raw_read_lock_irq(rwlock_t *lock)	__acquires(lock);
  void __lockfunc _raw_write_lock_irq(rwlock_t *lock)	__acquires(lock);
  unsigned long __lockfunc _raw_read_lock_irqsave(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
24
  							__acquires(lock);
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
25
  unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
26
  							__acquires(lock);
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
27
28
29
30
31
32
33
34
35
36
  int __lockfunc _raw_read_trylock(rwlock_t *lock);
  int __lockfunc _raw_write_trylock(rwlock_t *lock);
  void __lockfunc _raw_read_unlock(rwlock_t *lock)	__releases(lock);
  void __lockfunc _raw_write_unlock(rwlock_t *lock)	__releases(lock);
  void __lockfunc _raw_read_unlock_bh(rwlock_t *lock)	__releases(lock);
  void __lockfunc _raw_write_unlock_bh(rwlock_t *lock)	__releases(lock);
  void __lockfunc _raw_read_unlock_irq(rwlock_t *lock)	__releases(lock);
  void __lockfunc _raw_write_unlock_irq(rwlock_t *lock)	__releases(lock);
  void __lockfunc
  _raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
6b6b4792f   Thomas Gleixner   locking: Separate...
37
  							__releases(lock);
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
38
39
  void __lockfunc
  _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
6b6b4792f   Thomas Gleixner   locking: Separate...
40
41
42
  							__releases(lock);
  
  #ifdef CONFIG_INLINE_READ_LOCK
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
43
  #define _raw_read_lock(lock) __raw_read_lock(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
44
45
46
  #endif
  
  #ifdef CONFIG_INLINE_WRITE_LOCK
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
47
  #define _raw_write_lock(lock) __raw_write_lock(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
48
49
50
  #endif
  
  #ifdef CONFIG_INLINE_READ_LOCK_BH
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
51
  #define _raw_read_lock_bh(lock) __raw_read_lock_bh(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
52
53
54
  #endif
  
  #ifdef CONFIG_INLINE_WRITE_LOCK_BH
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
55
  #define _raw_write_lock_bh(lock) __raw_write_lock_bh(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
56
57
58
  #endif
  
  #ifdef CONFIG_INLINE_READ_LOCK_IRQ
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
59
  #define _raw_read_lock_irq(lock) __raw_read_lock_irq(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
60
61
62
  #endif
  
  #ifdef CONFIG_INLINE_WRITE_LOCK_IRQ
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
63
  #define _raw_write_lock_irq(lock) __raw_write_lock_irq(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
64
65
66
  #endif
  
  #ifdef CONFIG_INLINE_READ_LOCK_IRQSAVE
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
67
  #define _raw_read_lock_irqsave(lock) __raw_read_lock_irqsave(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
68
69
70
  #endif
  
  #ifdef CONFIG_INLINE_WRITE_LOCK_IRQSAVE
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
71
  #define _raw_write_lock_irqsave(lock) __raw_write_lock_irqsave(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
72
73
74
  #endif
  
  #ifdef CONFIG_INLINE_READ_TRYLOCK
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
75
  #define _raw_read_trylock(lock) __raw_read_trylock(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
76
77
78
  #endif
  
  #ifdef CONFIG_INLINE_WRITE_TRYLOCK
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
79
  #define _raw_write_trylock(lock) __raw_write_trylock(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
80
81
82
  #endif
  
  #ifdef CONFIG_INLINE_READ_UNLOCK
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
83
  #define _raw_read_unlock(lock) __raw_read_unlock(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
84
85
86
  #endif
  
  #ifdef CONFIG_INLINE_WRITE_UNLOCK
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
87
  #define _raw_write_unlock(lock) __raw_write_unlock(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
88
89
90
  #endif
  
  #ifdef CONFIG_INLINE_READ_UNLOCK_BH
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
91
  #define _raw_read_unlock_bh(lock) __raw_read_unlock_bh(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
92
93
94
  #endif
  
  #ifdef CONFIG_INLINE_WRITE_UNLOCK_BH
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
95
  #define _raw_write_unlock_bh(lock) __raw_write_unlock_bh(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
96
97
98
  #endif
  
  #ifdef CONFIG_INLINE_READ_UNLOCK_IRQ
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
99
  #define _raw_read_unlock_irq(lock) __raw_read_unlock_irq(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
100
101
102
  #endif
  
  #ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQ
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
103
  #define _raw_write_unlock_irq(lock) __raw_write_unlock_irq(lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
104
105
106
  #endif
  
  #ifdef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
107
108
  #define _raw_read_unlock_irqrestore(lock, flags) \
  	__raw_read_unlock_irqrestore(lock, flags)
6b6b4792f   Thomas Gleixner   locking: Separate...
109
110
111
  #endif
  
  #ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
112
113
  #define _raw_write_unlock_irqrestore(lock, flags) \
  	__raw_write_unlock_irqrestore(lock, flags)
6b6b4792f   Thomas Gleixner   locking: Separate...
114
  #endif
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
115
  static inline int __raw_read_trylock(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
116
117
  {
  	preempt_disable();
9828ea9d7   Thomas Gleixner   locking: Further ...
118
  	if (do_raw_read_trylock(lock)) {
6b6b4792f   Thomas Gleixner   locking: Separate...
119
120
121
122
123
124
  		rwlock_acquire_read(&lock->dep_map, 0, 1, _RET_IP_);
  		return 1;
  	}
  	preempt_enable();
  	return 0;
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
125
  static inline int __raw_write_trylock(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
126
127
  {
  	preempt_disable();
9828ea9d7   Thomas Gleixner   locking: Further ...
128
  	if (do_raw_write_trylock(lock)) {
6b6b4792f   Thomas Gleixner   locking: Separate...
129
130
131
132
133
134
135
136
137
138
139
140
141
  		rwlock_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  		return 1;
  	}
  	preempt_enable();
  	return 0;
  }
  
  /*
   * If lockdep is enabled then we use the non-preemption spin-ops
   * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are
   * not re-enabled during lock-acquire (which the preempt-spin-ops do):
   */
  #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
142
  static inline void __raw_read_lock(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
143
144
145
  {
  	preempt_disable();
  	rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
146
  	LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
147
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
148
  static inline unsigned long __raw_read_lock_irqsave(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
149
150
151
152
153
154
  {
  	unsigned long flags;
  
  	local_irq_save(flags);
  	preempt_disable();
  	rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
155
156
  	LOCK_CONTENDED_FLAGS(lock, do_raw_read_trylock, do_raw_read_lock,
  			     do_raw_read_lock_flags, &flags);
6b6b4792f   Thomas Gleixner   locking: Separate...
157
158
  	return flags;
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
159
  static inline void __raw_read_lock_irq(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
160
161
162
163
  {
  	local_irq_disable();
  	preempt_disable();
  	rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
164
  	LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
165
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
166
  static inline void __raw_read_lock_bh(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
167
168
169
170
  {
  	local_bh_disable();
  	preempt_disable();
  	rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
171
  	LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
172
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
173
  static inline unsigned long __raw_write_lock_irqsave(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
174
175
176
177
178
179
  {
  	unsigned long flags;
  
  	local_irq_save(flags);
  	preempt_disable();
  	rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
180
181
  	LOCK_CONTENDED_FLAGS(lock, do_raw_write_trylock, do_raw_write_lock,
  			     do_raw_write_lock_flags, &flags);
6b6b4792f   Thomas Gleixner   locking: Separate...
182
183
  	return flags;
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
184
  static inline void __raw_write_lock_irq(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
185
186
187
188
  {
  	local_irq_disable();
  	preempt_disable();
  	rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
189
  	LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
190
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
191
  static inline void __raw_write_lock_bh(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
192
193
194
195
  {
  	local_bh_disable();
  	preempt_disable();
  	rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
196
  	LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
197
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
198
  static inline void __raw_write_lock(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
199
200
201
  {
  	preempt_disable();
  	rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
202
  	LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
203
204
205
  }
  
  #endif /* CONFIG_PREEMPT */
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
206
  static inline void __raw_write_unlock(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
207
208
  {
  	rwlock_release(&lock->dep_map, 1, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
209
  	do_raw_write_unlock(lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
210
211
  	preempt_enable();
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
212
  static inline void __raw_read_unlock(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
213
214
  {
  	rwlock_release(&lock->dep_map, 1, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
215
  	do_raw_read_unlock(lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
216
217
  	preempt_enable();
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
218
219
  static inline void
  __raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
6b6b4792f   Thomas Gleixner   locking: Separate...
220
221
  {
  	rwlock_release(&lock->dep_map, 1, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
222
  	do_raw_read_unlock(lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
223
224
225
  	local_irq_restore(flags);
  	preempt_enable();
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
226
  static inline void __raw_read_unlock_irq(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
227
228
  {
  	rwlock_release(&lock->dep_map, 1, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
229
  	do_raw_read_unlock(lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
230
231
232
  	local_irq_enable();
  	preempt_enable();
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
233
  static inline void __raw_read_unlock_bh(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
234
235
  {
  	rwlock_release(&lock->dep_map, 1, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
236
  	do_raw_read_unlock(lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
237
238
239
  	preempt_enable_no_resched();
  	local_bh_enable_ip((unsigned long)__builtin_return_address(0));
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
240
  static inline void __raw_write_unlock_irqrestore(rwlock_t *lock,
6b6b4792f   Thomas Gleixner   locking: Separate...
241
242
243
  					     unsigned long flags)
  {
  	rwlock_release(&lock->dep_map, 1, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
244
  	do_raw_write_unlock(lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
245
246
247
  	local_irq_restore(flags);
  	preempt_enable();
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
248
  static inline void __raw_write_unlock_irq(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
249
250
  {
  	rwlock_release(&lock->dep_map, 1, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
251
  	do_raw_write_unlock(lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
252
253
254
  	local_irq_enable();
  	preempt_enable();
  }
9c1721aa4   Thomas Gleixner   locking: Cleanup ...
255
  static inline void __raw_write_unlock_bh(rwlock_t *lock)
6b6b4792f   Thomas Gleixner   locking: Separate...
256
257
  {
  	rwlock_release(&lock->dep_map, 1, _RET_IP_);
9828ea9d7   Thomas Gleixner   locking: Further ...
258
  	do_raw_write_unlock(lock);
6b6b4792f   Thomas Gleixner   locking: Separate...
259
260
261
262
263
  	preempt_enable_no_resched();
  	local_bh_enable_ip((unsigned long)__builtin_return_address(0));
  }
  
  #endif /* __LINUX_RWLOCK_API_SMP_H */