blob: 7932653c4ebde88e7010ec1da9601ef974e8c3bb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (2004) Linus Torvalds
3 *
4 * Author: Zwane Mwaikambo <zwane@fsmlabs.com>
5 *
Ingo Molnarfb1c8f92005-09-10 00:25:56 -07006 * Copyright (2004, 2005) Ingo Molnar
7 *
8 * This file contains the spinlock/rwlock implementations for the
9 * SMP and the DEBUG_SPINLOCK cases. (UP-nondebug inlines them)
Andi Kleen0cb91a22006-09-26 10:52:28 +020010 *
11 * Note that some architectures have special knowledge about the
12 * stack frames of these functions in their profile_pc. If you
13 * change anything significant here that could change the stack
14 * frame contact the architecture maintainers.
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 */
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/linkage.h>
18#include <linux/preempt.h>
19#include <linux/spinlock.h>
20#include <linux/interrupt.h>
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070021#include <linux/debug_locks.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024int __lockfunc _spin_trylock(spinlock_t *lock)
25{
26 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070027 if (_raw_spin_trylock(lock)) {
28 spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 return 1;
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32 preempt_enable();
33 return 0;
34}
35EXPORT_SYMBOL(_spin_trylock);
36
37int __lockfunc _read_trylock(rwlock_t *lock)
38{
39 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070040 if (_raw_read_trylock(lock)) {
41 rwlock_acquire_read(&lock->dep_map, 0, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 return 1;
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070043 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 preempt_enable();
46 return 0;
47}
48EXPORT_SYMBOL(_read_trylock);
49
50int __lockfunc _write_trylock(rwlock_t *lock)
51{
52 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070053 if (_raw_write_trylock(lock)) {
54 rwlock_acquire(&lock->dep_map, 0, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return 1;
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58 preempt_enable();
59 return 0;
60}
61EXPORT_SYMBOL(_write_trylock);
62
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070063/*
64 * If lockdep is enabled then we use the non-preemption spin-ops
65 * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are
66 * not re-enabled during lock-acquire (which the preempt-spin-ops do):
67 */
Nick Piggin95c354f2008-01-30 13:31:20 +010068#if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70void __lockfunc _read_lock(rwlock_t *lock)
71{
72 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070073 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
Peter Zijlstra4fe87742007-07-19 01:48:58 -070074 LOCK_CONTENDED(lock, _raw_read_trylock, _raw_read_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76EXPORT_SYMBOL(_read_lock);
77
78unsigned long __lockfunc _spin_lock_irqsave(spinlock_t *lock)
79{
80 unsigned long flags;
81
82 local_irq_save(flags);
83 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070084 spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
85 /*
86 * On lockdep we dont want the hand-coded irq-enable of
87 * _raw_spin_lock_flags() code, because lockdep assumes
88 * that interrupts are not re-enabled during lock-acquire:
89 */
Peter Zijlstraca58abc2007-07-19 01:48:53 -070090#ifdef CONFIG_LOCKDEP
Peter Zijlstra4fe87742007-07-19 01:48:58 -070091 LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock);
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070092#else
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070093 _raw_spin_lock_flags(lock, &flags);
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070094#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 return flags;
96}
97EXPORT_SYMBOL(_spin_lock_irqsave);
98
99void __lockfunc _spin_lock_irq(spinlock_t *lock)
100{
101 local_irq_disable();
102 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700103 spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Peter Zijlstra4fe87742007-07-19 01:48:58 -0700104 LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106EXPORT_SYMBOL(_spin_lock_irq);
107
108void __lockfunc _spin_lock_bh(spinlock_t *lock)
109{
110 local_bh_disable();
111 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700112 spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Peter Zijlstra4fe87742007-07-19 01:48:58 -0700113 LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115EXPORT_SYMBOL(_spin_lock_bh);
116
117unsigned long __lockfunc _read_lock_irqsave(rwlock_t *lock)
118{
119 unsigned long flags;
120
121 local_irq_save(flags);
122 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700123 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
Robin Holtf5f7eac2009-04-02 16:59:46 -0700124 LOCK_CONTENDED_FLAGS(lock, _raw_read_trylock, _raw_read_lock,
125 _raw_read_lock_flags, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 return flags;
127}
128EXPORT_SYMBOL(_read_lock_irqsave);
129
130void __lockfunc _read_lock_irq(rwlock_t *lock)
131{
132 local_irq_disable();
133 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700134 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
Peter Zijlstra4fe87742007-07-19 01:48:58 -0700135 LOCK_CONTENDED(lock, _raw_read_trylock, _raw_read_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137EXPORT_SYMBOL(_read_lock_irq);
138
139void __lockfunc _read_lock_bh(rwlock_t *lock)
140{
141 local_bh_disable();
142 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700143 rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
Peter Zijlstra4fe87742007-07-19 01:48:58 -0700144 LOCK_CONTENDED(lock, _raw_read_trylock, _raw_read_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146EXPORT_SYMBOL(_read_lock_bh);
147
148unsigned long __lockfunc _write_lock_irqsave(rwlock_t *lock)
149{
150 unsigned long flags;
151
152 local_irq_save(flags);
153 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700154 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Robin Holtf5f7eac2009-04-02 16:59:46 -0700155 LOCK_CONTENDED_FLAGS(lock, _raw_write_trylock, _raw_write_lock,
156 _raw_write_lock_flags, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 return flags;
158}
159EXPORT_SYMBOL(_write_lock_irqsave);
160
161void __lockfunc _write_lock_irq(rwlock_t *lock)
162{
163 local_irq_disable();
164 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700165 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Peter Zijlstra4fe87742007-07-19 01:48:58 -0700166 LOCK_CONTENDED(lock, _raw_write_trylock, _raw_write_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168EXPORT_SYMBOL(_write_lock_irq);
169
170void __lockfunc _write_lock_bh(rwlock_t *lock)
171{
172 local_bh_disable();
173 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700174 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Peter Zijlstra4fe87742007-07-19 01:48:58 -0700175 LOCK_CONTENDED(lock, _raw_write_trylock, _raw_write_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177EXPORT_SYMBOL(_write_lock_bh);
178
179void __lockfunc _spin_lock(spinlock_t *lock)
180{
181 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700182 spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Peter Zijlstra4fe87742007-07-19 01:48:58 -0700183 LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
186EXPORT_SYMBOL(_spin_lock);
187
188void __lockfunc _write_lock(rwlock_t *lock)
189{
190 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700191 rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Peter Zijlstra4fe87742007-07-19 01:48:58 -0700192 LOCK_CONTENDED(lock, _raw_write_trylock, _raw_write_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
195EXPORT_SYMBOL(_write_lock);
196
197#else /* CONFIG_PREEMPT: */
198
199/*
200 * This could be a long-held lock. We both prepare to spin for a long
201 * time (making _this_ CPU preemptable if possible), and we also signal
202 * towards that other CPU that it should break the lock ASAP.
203 *
204 * (We do this in a function because inlining it would be excessive.)
205 */
206
207#define BUILD_LOCK_OPS(op, locktype) \
208void __lockfunc _##op##_lock(locktype##_t *lock) \
209{ \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 for (;;) { \
Oleg Nesterovee25e962006-03-23 03:00:58 -0800211 preempt_disable(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 if (likely(_raw_##op##_trylock(lock))) \
213 break; \
214 preempt_enable(); \
Oleg Nesterovee25e962006-03-23 03:00:58 -0800215 \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 if (!(lock)->break_lock) \
217 (lock)->break_lock = 1; \
218 while (!op##_can_lock(lock) && (lock)->break_lock) \
Martin Schwidefskyef6edc92006-09-30 23:27:43 -0700219 _raw_##op##_relax(&lock->raw_lock); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 } \
221 (lock)->break_lock = 0; \
222} \
223 \
224EXPORT_SYMBOL(_##op##_lock); \
225 \
226unsigned long __lockfunc _##op##_lock_irqsave(locktype##_t *lock) \
227{ \
228 unsigned long flags; \
229 \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 for (;;) { \
Oleg Nesterovee25e962006-03-23 03:00:58 -0800231 preempt_disable(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 local_irq_save(flags); \
233 if (likely(_raw_##op##_trylock(lock))) \
234 break; \
235 local_irq_restore(flags); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 preempt_enable(); \
Oleg Nesterovee25e962006-03-23 03:00:58 -0800237 \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 if (!(lock)->break_lock) \
239 (lock)->break_lock = 1; \
240 while (!op##_can_lock(lock) && (lock)->break_lock) \
Martin Schwidefskyef6edc92006-09-30 23:27:43 -0700241 _raw_##op##_relax(&lock->raw_lock); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 } \
243 (lock)->break_lock = 0; \
244 return flags; \
245} \
246 \
247EXPORT_SYMBOL(_##op##_lock_irqsave); \
248 \
249void __lockfunc _##op##_lock_irq(locktype##_t *lock) \
250{ \
251 _##op##_lock_irqsave(lock); \
252} \
253 \
254EXPORT_SYMBOL(_##op##_lock_irq); \
255 \
256void __lockfunc _##op##_lock_bh(locktype##_t *lock) \
257{ \
258 unsigned long flags; \
259 \
260 /* */ \
261 /* Careful: we must exclude softirqs too, hence the */ \
262 /* irq-disabling. We use the generic preemption-aware */ \
263 /* function: */ \
264 /**/ \
265 flags = _##op##_lock_irqsave(lock); \
266 local_bh_disable(); \
267 local_irq_restore(flags); \
268} \
269 \
270EXPORT_SYMBOL(_##op##_lock_bh)
271
272/*
273 * Build preemption-friendly versions of the following
274 * lock-spinning functions:
275 *
276 * _[spin|read|write]_lock()
277 * _[spin|read|write]_lock_irq()
278 * _[spin|read|write]_lock_irqsave()
279 * _[spin|read|write]_lock_bh()
280 */
281BUILD_LOCK_OPS(spin, spinlock);
282BUILD_LOCK_OPS(read, rwlock);
283BUILD_LOCK_OPS(write, rwlock);
284
285#endif /* CONFIG_PREEMPT */
286
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700287#ifdef CONFIG_DEBUG_LOCK_ALLOC
288
289void __lockfunc _spin_lock_nested(spinlock_t *lock, int subclass)
290{
291 preempt_disable();
292 spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
Peter Zijlstra4fe87742007-07-19 01:48:58 -0700293 LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock);
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700294}
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700295EXPORT_SYMBOL(_spin_lock_nested);
Peter Zijlstrab7d39af2008-08-11 09:30:24 +0200296
Arjan van de Vencfd3ef22006-11-25 11:09:37 -0800297unsigned long __lockfunc _spin_lock_irqsave_nested(spinlock_t *lock, int subclass)
298{
299 unsigned long flags;
300
301 local_irq_save(flags);
302 preempt_disable();
303 spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
Robin Holte8c158b2009-04-02 16:59:45 -0700304 LOCK_CONTENDED_FLAGS(lock, _raw_spin_trylock, _raw_spin_lock,
305 _raw_spin_lock_flags, &flags);
Arjan van de Vencfd3ef22006-11-25 11:09:37 -0800306 return flags;
307}
Arjan van de Vencfd3ef22006-11-25 11:09:37 -0800308EXPORT_SYMBOL(_spin_lock_irqsave_nested);
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700309
Peter Zijlstrab7d39af2008-08-11 09:30:24 +0200310void __lockfunc _spin_lock_nest_lock(spinlock_t *lock,
311 struct lockdep_map *nest_lock)
312{
313 preempt_disable();
314 spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_);
315 LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock);
316}
Peter Zijlstrab7d39af2008-08-11 09:30:24 +0200317EXPORT_SYMBOL(_spin_lock_nest_lock);
318
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700319#endif
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321void __lockfunc _spin_unlock(spinlock_t *lock)
322{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700323 spin_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 _raw_spin_unlock(lock);
325 preempt_enable();
326}
327EXPORT_SYMBOL(_spin_unlock);
328
329void __lockfunc _write_unlock(rwlock_t *lock)
330{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700331 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 _raw_write_unlock(lock);
333 preempt_enable();
334}
335EXPORT_SYMBOL(_write_unlock);
336
337void __lockfunc _read_unlock(rwlock_t *lock)
338{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700339 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 _raw_read_unlock(lock);
341 preempt_enable();
342}
343EXPORT_SYMBOL(_read_unlock);
344
345void __lockfunc _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags)
346{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700347 spin_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 _raw_spin_unlock(lock);
349 local_irq_restore(flags);
350 preempt_enable();
351}
352EXPORT_SYMBOL(_spin_unlock_irqrestore);
353
354void __lockfunc _spin_unlock_irq(spinlock_t *lock)
355{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700356 spin_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 _raw_spin_unlock(lock);
358 local_irq_enable();
359 preempt_enable();
360}
361EXPORT_SYMBOL(_spin_unlock_irq);
362
363void __lockfunc _spin_unlock_bh(spinlock_t *lock)
364{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700365 spin_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 _raw_spin_unlock(lock);
Samuel Thibault10f02d1c2005-05-21 17:50:15 +0200367 preempt_enable_no_resched();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700368 local_bh_enable_ip((unsigned long)__builtin_return_address(0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369}
370EXPORT_SYMBOL(_spin_unlock_bh);
371
372void __lockfunc _read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
373{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700374 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 _raw_read_unlock(lock);
376 local_irq_restore(flags);
377 preempt_enable();
378}
379EXPORT_SYMBOL(_read_unlock_irqrestore);
380
381void __lockfunc _read_unlock_irq(rwlock_t *lock)
382{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700383 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 _raw_read_unlock(lock);
385 local_irq_enable();
386 preempt_enable();
387}
388EXPORT_SYMBOL(_read_unlock_irq);
389
390void __lockfunc _read_unlock_bh(rwlock_t *lock)
391{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700392 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 _raw_read_unlock(lock);
Samuel Thibault10f02d1c2005-05-21 17:50:15 +0200394 preempt_enable_no_resched();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700395 local_bh_enable_ip((unsigned long)__builtin_return_address(0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396}
397EXPORT_SYMBOL(_read_unlock_bh);
398
399void __lockfunc _write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
400{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700401 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 _raw_write_unlock(lock);
403 local_irq_restore(flags);
404 preempt_enable();
405}
406EXPORT_SYMBOL(_write_unlock_irqrestore);
407
408void __lockfunc _write_unlock_irq(rwlock_t *lock)
409{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700410 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 _raw_write_unlock(lock);
412 local_irq_enable();
413 preempt_enable();
414}
415EXPORT_SYMBOL(_write_unlock_irq);
416
417void __lockfunc _write_unlock_bh(rwlock_t *lock)
418{
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700419 rwlock_release(&lock->dep_map, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 _raw_write_unlock(lock);
Samuel Thibault10f02d1c2005-05-21 17:50:15 +0200421 preempt_enable_no_resched();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700422 local_bh_enable_ip((unsigned long)__builtin_return_address(0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423}
424EXPORT_SYMBOL(_write_unlock_bh);
425
426int __lockfunc _spin_trylock_bh(spinlock_t *lock)
427{
428 local_bh_disable();
429 preempt_disable();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700430 if (_raw_spin_trylock(lock)) {
431 spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return 1;
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700433 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Samuel Thibault10f02d1c2005-05-21 17:50:15 +0200435 preempt_enable_no_resched();
Ingo Molnar8a25d5d2006-07-03 00:24:54 -0700436 local_bh_enable_ip((unsigned long)__builtin_return_address(0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 return 0;
438}
439EXPORT_SYMBOL(_spin_trylock_bh);
440
Steven Rostedt0764d232008-05-12 21:20:44 +0200441notrace int in_lock_functions(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
443 /* Linker adds these: start and end of __lockfunc functions */
444 extern char __lock_text_start[], __lock_text_end[];
445
446 return addr >= (unsigned long)__lock_text_start
447 && addr < (unsigned long)__lock_text_end;
448}
449EXPORT_SYMBOL(in_lock_functions);