Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (2004) Linus Torvalds |
| 3 | * |
| 4 | * Author: Zwane Mwaikambo <zwane@fsmlabs.com> |
| 5 | * |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 6 | * 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 Kleen | 0cb91a2 | 2006-09-26 10:52:28 +0200 | [diff] [blame] | 10 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/linkage.h> |
| 18 | #include <linux/preempt.h> |
| 19 | #include <linux/spinlock.h> |
| 20 | #include <linux/interrupt.h> |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 21 | #include <linux/debug_locks.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | int __lockfunc _spin_trylock(spinlock_t *lock) |
| 25 | { |
| 26 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 27 | if (_raw_spin_trylock(lock)) { |
| 28 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | return 1; |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 30 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | preempt_enable(); |
| 33 | return 0; |
| 34 | } |
| 35 | EXPORT_SYMBOL(_spin_trylock); |
| 36 | |
| 37 | int __lockfunc _read_trylock(rwlock_t *lock) |
| 38 | { |
| 39 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 40 | if (_raw_read_trylock(lock)) { |
| 41 | rwlock_acquire_read(&lock->dep_map, 0, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | return 1; |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 43 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | preempt_enable(); |
| 46 | return 0; |
| 47 | } |
| 48 | EXPORT_SYMBOL(_read_trylock); |
| 49 | |
| 50 | int __lockfunc _write_trylock(rwlock_t *lock) |
| 51 | { |
| 52 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 53 | if (_raw_write_trylock(lock)) { |
| 54 | rwlock_acquire(&lock->dep_map, 0, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | return 1; |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 56 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | preempt_enable(); |
| 59 | return 0; |
| 60 | } |
| 61 | EXPORT_SYMBOL(_write_trylock); |
| 62 | |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 63 | /* |
| 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 | */ |
| 68 | #if !defined(CONFIG_PREEMPT) || !defined(CONFIG_SMP) || \ |
Jarek Poplawski | fc47e7b | 2006-09-06 00:03:39 -0700 | [diff] [blame] | 69 | defined(CONFIG_DEBUG_LOCK_ALLOC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | void __lockfunc _read_lock(rwlock_t *lock) |
| 72 | { |
| 73 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 74 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | _raw_read_lock(lock); |
| 76 | } |
| 77 | EXPORT_SYMBOL(_read_lock); |
| 78 | |
| 79 | unsigned long __lockfunc _spin_lock_irqsave(spinlock_t *lock) |
| 80 | { |
| 81 | unsigned long flags; |
| 82 | |
| 83 | local_irq_save(flags); |
| 84 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 85 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
| 86 | /* |
| 87 | * On lockdep we dont want the hand-coded irq-enable of |
| 88 | * _raw_spin_lock_flags() code, because lockdep assumes |
| 89 | * that interrupts are not re-enabled during lock-acquire: |
| 90 | */ |
Peter Zijlstra | ca58abc | 2007-07-19 01:48:53 -0700 | [diff] [blame^] | 91 | #ifdef CONFIG_LOCKDEP |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 92 | _raw_spin_lock(lock); |
| 93 | #else |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 94 | _raw_spin_lock_flags(lock, &flags); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 95 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return flags; |
| 97 | } |
| 98 | EXPORT_SYMBOL(_spin_lock_irqsave); |
| 99 | |
| 100 | void __lockfunc _spin_lock_irq(spinlock_t *lock) |
| 101 | { |
| 102 | local_irq_disable(); |
| 103 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 104 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | _raw_spin_lock(lock); |
| 106 | } |
| 107 | EXPORT_SYMBOL(_spin_lock_irq); |
| 108 | |
| 109 | void __lockfunc _spin_lock_bh(spinlock_t *lock) |
| 110 | { |
| 111 | local_bh_disable(); |
| 112 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 113 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | _raw_spin_lock(lock); |
| 115 | } |
| 116 | EXPORT_SYMBOL(_spin_lock_bh); |
| 117 | |
| 118 | unsigned long __lockfunc _read_lock_irqsave(rwlock_t *lock) |
| 119 | { |
| 120 | unsigned long flags; |
| 121 | |
| 122 | local_irq_save(flags); |
| 123 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 124 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | _raw_read_lock(lock); |
| 126 | return flags; |
| 127 | } |
| 128 | EXPORT_SYMBOL(_read_lock_irqsave); |
| 129 | |
| 130 | void __lockfunc _read_lock_irq(rwlock_t *lock) |
| 131 | { |
| 132 | local_irq_disable(); |
| 133 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 134 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | _raw_read_lock(lock); |
| 136 | } |
| 137 | EXPORT_SYMBOL(_read_lock_irq); |
| 138 | |
| 139 | void __lockfunc _read_lock_bh(rwlock_t *lock) |
| 140 | { |
| 141 | local_bh_disable(); |
| 142 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 143 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | _raw_read_lock(lock); |
| 145 | } |
| 146 | EXPORT_SYMBOL(_read_lock_bh); |
| 147 | |
| 148 | unsigned long __lockfunc _write_lock_irqsave(rwlock_t *lock) |
| 149 | { |
| 150 | unsigned long flags; |
| 151 | |
| 152 | local_irq_save(flags); |
| 153 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 154 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | _raw_write_lock(lock); |
| 156 | return flags; |
| 157 | } |
| 158 | EXPORT_SYMBOL(_write_lock_irqsave); |
| 159 | |
| 160 | void __lockfunc _write_lock_irq(rwlock_t *lock) |
| 161 | { |
| 162 | local_irq_disable(); |
| 163 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 164 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | _raw_write_lock(lock); |
| 166 | } |
| 167 | EXPORT_SYMBOL(_write_lock_irq); |
| 168 | |
| 169 | void __lockfunc _write_lock_bh(rwlock_t *lock) |
| 170 | { |
| 171 | local_bh_disable(); |
| 172 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 173 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | _raw_write_lock(lock); |
| 175 | } |
| 176 | EXPORT_SYMBOL(_write_lock_bh); |
| 177 | |
| 178 | void __lockfunc _spin_lock(spinlock_t *lock) |
| 179 | { |
| 180 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 181 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | _raw_spin_lock(lock); |
| 183 | } |
| 184 | |
| 185 | EXPORT_SYMBOL(_spin_lock); |
| 186 | |
| 187 | void __lockfunc _write_lock(rwlock_t *lock) |
| 188 | { |
| 189 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 190 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | _raw_write_lock(lock); |
| 192 | } |
| 193 | |
| 194 | EXPORT_SYMBOL(_write_lock); |
| 195 | |
| 196 | #else /* CONFIG_PREEMPT: */ |
| 197 | |
| 198 | /* |
| 199 | * This could be a long-held lock. We both prepare to spin for a long |
| 200 | * time (making _this_ CPU preemptable if possible), and we also signal |
| 201 | * towards that other CPU that it should break the lock ASAP. |
| 202 | * |
| 203 | * (We do this in a function because inlining it would be excessive.) |
| 204 | */ |
| 205 | |
| 206 | #define BUILD_LOCK_OPS(op, locktype) \ |
| 207 | void __lockfunc _##op##_lock(locktype##_t *lock) \ |
| 208 | { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | for (;;) { \ |
Oleg Nesterov | ee25e96 | 2006-03-23 03:00:58 -0800 | [diff] [blame] | 210 | preempt_disable(); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | if (likely(_raw_##op##_trylock(lock))) \ |
| 212 | break; \ |
| 213 | preempt_enable(); \ |
Oleg Nesterov | ee25e96 | 2006-03-23 03:00:58 -0800 | [diff] [blame] | 214 | \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | if (!(lock)->break_lock) \ |
| 216 | (lock)->break_lock = 1; \ |
| 217 | while (!op##_can_lock(lock) && (lock)->break_lock) \ |
Martin Schwidefsky | ef6edc9 | 2006-09-30 23:27:43 -0700 | [diff] [blame] | 218 | _raw_##op##_relax(&lock->raw_lock); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } \ |
| 220 | (lock)->break_lock = 0; \ |
| 221 | } \ |
| 222 | \ |
| 223 | EXPORT_SYMBOL(_##op##_lock); \ |
| 224 | \ |
| 225 | unsigned long __lockfunc _##op##_lock_irqsave(locktype##_t *lock) \ |
| 226 | { \ |
| 227 | unsigned long flags; \ |
| 228 | \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | for (;;) { \ |
Oleg Nesterov | ee25e96 | 2006-03-23 03:00:58 -0800 | [diff] [blame] | 230 | preempt_disable(); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | local_irq_save(flags); \ |
| 232 | if (likely(_raw_##op##_trylock(lock))) \ |
| 233 | break; \ |
| 234 | local_irq_restore(flags); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | preempt_enable(); \ |
Oleg Nesterov | ee25e96 | 2006-03-23 03:00:58 -0800 | [diff] [blame] | 236 | \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | if (!(lock)->break_lock) \ |
| 238 | (lock)->break_lock = 1; \ |
| 239 | while (!op##_can_lock(lock) && (lock)->break_lock) \ |
Martin Schwidefsky | ef6edc9 | 2006-09-30 23:27:43 -0700 | [diff] [blame] | 240 | _raw_##op##_relax(&lock->raw_lock); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } \ |
| 242 | (lock)->break_lock = 0; \ |
| 243 | return flags; \ |
| 244 | } \ |
| 245 | \ |
| 246 | EXPORT_SYMBOL(_##op##_lock_irqsave); \ |
| 247 | \ |
| 248 | void __lockfunc _##op##_lock_irq(locktype##_t *lock) \ |
| 249 | { \ |
| 250 | _##op##_lock_irqsave(lock); \ |
| 251 | } \ |
| 252 | \ |
| 253 | EXPORT_SYMBOL(_##op##_lock_irq); \ |
| 254 | \ |
| 255 | void __lockfunc _##op##_lock_bh(locktype##_t *lock) \ |
| 256 | { \ |
| 257 | unsigned long flags; \ |
| 258 | \ |
| 259 | /* */ \ |
| 260 | /* Careful: we must exclude softirqs too, hence the */ \ |
| 261 | /* irq-disabling. We use the generic preemption-aware */ \ |
| 262 | /* function: */ \ |
| 263 | /**/ \ |
| 264 | flags = _##op##_lock_irqsave(lock); \ |
| 265 | local_bh_disable(); \ |
| 266 | local_irq_restore(flags); \ |
| 267 | } \ |
| 268 | \ |
| 269 | EXPORT_SYMBOL(_##op##_lock_bh) |
| 270 | |
| 271 | /* |
| 272 | * Build preemption-friendly versions of the following |
| 273 | * lock-spinning functions: |
| 274 | * |
| 275 | * _[spin|read|write]_lock() |
| 276 | * _[spin|read|write]_lock_irq() |
| 277 | * _[spin|read|write]_lock_irqsave() |
| 278 | * _[spin|read|write]_lock_bh() |
| 279 | */ |
| 280 | BUILD_LOCK_OPS(spin, spinlock); |
| 281 | BUILD_LOCK_OPS(read, rwlock); |
| 282 | BUILD_LOCK_OPS(write, rwlock); |
| 283 | |
| 284 | #endif /* CONFIG_PREEMPT */ |
| 285 | |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 286 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 287 | |
| 288 | void __lockfunc _spin_lock_nested(spinlock_t *lock, int subclass) |
| 289 | { |
| 290 | preempt_disable(); |
| 291 | spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_); |
| 292 | _raw_spin_lock(lock); |
| 293 | } |
| 294 | |
| 295 | EXPORT_SYMBOL(_spin_lock_nested); |
Arjan van de Ven | cfd3ef2 | 2006-11-25 11:09:37 -0800 | [diff] [blame] | 296 | unsigned long __lockfunc _spin_lock_irqsave_nested(spinlock_t *lock, int subclass) |
| 297 | { |
| 298 | unsigned long flags; |
| 299 | |
| 300 | local_irq_save(flags); |
| 301 | preempt_disable(); |
| 302 | spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_); |
| 303 | /* |
| 304 | * On lockdep we dont want the hand-coded irq-enable of |
| 305 | * _raw_spin_lock_flags() code, because lockdep assumes |
| 306 | * that interrupts are not re-enabled during lock-acquire: |
| 307 | */ |
Peter Zijlstra | ca58abc | 2007-07-19 01:48:53 -0700 | [diff] [blame^] | 308 | #ifdef CONFIG_LOCKDEP |
Arjan van de Ven | cfd3ef2 | 2006-11-25 11:09:37 -0800 | [diff] [blame] | 309 | _raw_spin_lock(lock); |
| 310 | #else |
| 311 | _raw_spin_lock_flags(lock, &flags); |
| 312 | #endif |
| 313 | return flags; |
| 314 | } |
| 315 | |
| 316 | EXPORT_SYMBOL(_spin_lock_irqsave_nested); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 317 | |
| 318 | #endif |
| 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | void __lockfunc _spin_unlock(spinlock_t *lock) |
| 321 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 322 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | _raw_spin_unlock(lock); |
| 324 | preempt_enable(); |
| 325 | } |
| 326 | EXPORT_SYMBOL(_spin_unlock); |
| 327 | |
| 328 | void __lockfunc _write_unlock(rwlock_t *lock) |
| 329 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 330 | rwlock_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | _raw_write_unlock(lock); |
| 332 | preempt_enable(); |
| 333 | } |
| 334 | EXPORT_SYMBOL(_write_unlock); |
| 335 | |
| 336 | void __lockfunc _read_unlock(rwlock_t *lock) |
| 337 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 338 | rwlock_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | _raw_read_unlock(lock); |
| 340 | preempt_enable(); |
| 341 | } |
| 342 | EXPORT_SYMBOL(_read_unlock); |
| 343 | |
| 344 | void __lockfunc _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags) |
| 345 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 346 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | _raw_spin_unlock(lock); |
| 348 | local_irq_restore(flags); |
| 349 | preempt_enable(); |
| 350 | } |
| 351 | EXPORT_SYMBOL(_spin_unlock_irqrestore); |
| 352 | |
| 353 | void __lockfunc _spin_unlock_irq(spinlock_t *lock) |
| 354 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 355 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | _raw_spin_unlock(lock); |
| 357 | local_irq_enable(); |
| 358 | preempt_enable(); |
| 359 | } |
| 360 | EXPORT_SYMBOL(_spin_unlock_irq); |
| 361 | |
| 362 | void __lockfunc _spin_unlock_bh(spinlock_t *lock) |
| 363 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 364 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | _raw_spin_unlock(lock); |
Samuel Thibault | 10f02d1c | 2005-05-21 17:50:15 +0200 | [diff] [blame] | 366 | preempt_enable_no_resched(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 367 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
| 369 | EXPORT_SYMBOL(_spin_unlock_bh); |
| 370 | |
| 371 | void __lockfunc _read_unlock_irqrestore(rwlock_t *lock, unsigned long flags) |
| 372 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 373 | rwlock_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | _raw_read_unlock(lock); |
| 375 | local_irq_restore(flags); |
| 376 | preempt_enable(); |
| 377 | } |
| 378 | EXPORT_SYMBOL(_read_unlock_irqrestore); |
| 379 | |
| 380 | void __lockfunc _read_unlock_irq(rwlock_t *lock) |
| 381 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 382 | rwlock_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | _raw_read_unlock(lock); |
| 384 | local_irq_enable(); |
| 385 | preempt_enable(); |
| 386 | } |
| 387 | EXPORT_SYMBOL(_read_unlock_irq); |
| 388 | |
| 389 | void __lockfunc _read_unlock_bh(rwlock_t *lock) |
| 390 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 391 | rwlock_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | _raw_read_unlock(lock); |
Samuel Thibault | 10f02d1c | 2005-05-21 17:50:15 +0200 | [diff] [blame] | 393 | preempt_enable_no_resched(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 394 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
| 396 | EXPORT_SYMBOL(_read_unlock_bh); |
| 397 | |
| 398 | void __lockfunc _write_unlock_irqrestore(rwlock_t *lock, unsigned long flags) |
| 399 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 400 | rwlock_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | _raw_write_unlock(lock); |
| 402 | local_irq_restore(flags); |
| 403 | preempt_enable(); |
| 404 | } |
| 405 | EXPORT_SYMBOL(_write_unlock_irqrestore); |
| 406 | |
| 407 | void __lockfunc _write_unlock_irq(rwlock_t *lock) |
| 408 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 409 | rwlock_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | _raw_write_unlock(lock); |
| 411 | local_irq_enable(); |
| 412 | preempt_enable(); |
| 413 | } |
| 414 | EXPORT_SYMBOL(_write_unlock_irq); |
| 415 | |
| 416 | void __lockfunc _write_unlock_bh(rwlock_t *lock) |
| 417 | { |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 418 | rwlock_release(&lock->dep_map, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | _raw_write_unlock(lock); |
Samuel Thibault | 10f02d1c | 2005-05-21 17:50:15 +0200 | [diff] [blame] | 420 | preempt_enable_no_resched(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 421 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | EXPORT_SYMBOL(_write_unlock_bh); |
| 424 | |
| 425 | int __lockfunc _spin_trylock_bh(spinlock_t *lock) |
| 426 | { |
| 427 | local_bh_disable(); |
| 428 | preempt_disable(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 429 | if (_raw_spin_trylock(lock)) { |
| 430 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | return 1; |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Samuel Thibault | 10f02d1c | 2005-05-21 17:50:15 +0200 | [diff] [blame] | 434 | preempt_enable_no_resched(); |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 435 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | return 0; |
| 437 | } |
| 438 | EXPORT_SYMBOL(_spin_trylock_bh); |
| 439 | |
| 440 | int in_lock_functions(unsigned long addr) |
| 441 | { |
| 442 | /* Linker adds these: start and end of __lockfunc functions */ |
| 443 | extern char __lock_text_start[], __lock_text_end[]; |
| 444 | |
| 445 | return addr >= (unsigned long)__lock_text_start |
| 446 | && addr < (unsigned long)__lock_text_end; |
| 447 | } |
| 448 | EXPORT_SYMBOL(in_lock_functions); |