diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dec_and_lock.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/dec_and_lock.c b/lib/dec_and_lock.c index 347fa7ac2e8a..9555b68bb774 100644 --- a/lib/dec_and_lock.c +++ b/lib/dec_and_lock.c | |||
| @@ -33,3 +33,19 @@ int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) | |||
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | EXPORT_SYMBOL(_atomic_dec_and_lock); | 35 | EXPORT_SYMBOL(_atomic_dec_and_lock); |
| 36 | |||
| 37 | int _atomic_dec_and_lock_irqsave(atomic_t *atomic, spinlock_t *lock, | ||
| 38 | unsigned long *flags) | ||
| 39 | { | ||
| 40 | /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */ | ||
| 41 | if (atomic_add_unless(atomic, -1, 1)) | ||
| 42 | return 0; | ||
| 43 | |||
| 44 | /* Otherwise do it the slow way */ | ||
| 45 | spin_lock_irqsave(lock, *flags); | ||
| 46 | if (atomic_dec_and_test(atomic)) | ||
| 47 | return 1; | ||
| 48 | spin_unlock_irqrestore(lock, *flags); | ||
| 49 | return 0; | ||
| 50 | } | ||
| 51 | EXPORT_SYMBOL(_atomic_dec_and_lock_irqsave); | ||
