diff options
author | Anna-Maria Gleixner <anna-maria@linutronix.de> | 2018-06-12 12:16:21 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2018-06-12 17:33:25 -0400 |
commit | 7ea959c45769612aa92557fb6464679f5fec7d9e (patch) | |
tree | 59727b6ac6c32a2addb41cab2c875ab7caee1b75 /lib/refcount.c | |
parent | ccfbb5bed407053b27492a9adc06064d949a9aa6 (diff) |
locking/refcounts: Implement refcount_dec_and_lock_irqsave()
There are in-tree users of refcount_dec_and_lock() which must acquire the
spin lock with interrupts disabled. To workaround the lack of an irqsave
variant of refcount_dec_and_lock() they use local_irq_save() at the call
site. This causes extra code and creates in some places unneeded long
interrupt disabled times. These places need also extra treatment for
PREEMPT_RT due to the disconnect of the irq disabling and the lock
function.
Implement the missing irqsave variant of the function.
Signed-off-by: Anna-Maria Gleixner <anna-maria@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r20180612161621.22645-4-bigeasy@linutronix.de
[bigeasy: s@atomic_dec_and_lock@refcount_dec_and_lock@g]
Diffstat (limited to 'lib/refcount.c')
-rw-r--r-- | lib/refcount.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/refcount.c b/lib/refcount.c index 0eb48353abe3..d3b81cefce91 100644 --- a/lib/refcount.c +++ b/lib/refcount.c | |||
@@ -350,3 +350,31 @@ bool refcount_dec_and_lock(refcount_t *r, spinlock_t *lock) | |||
350 | } | 350 | } |
351 | EXPORT_SYMBOL(refcount_dec_and_lock); | 351 | EXPORT_SYMBOL(refcount_dec_and_lock); |
352 | 352 | ||
353 | /** | ||
354 | * refcount_dec_and_lock_irqsave - return holding spinlock with disabled | ||
355 | * interrupts if able to decrement refcount to 0 | ||
356 | * @r: the refcount | ||
357 | * @lock: the spinlock to be locked | ||
358 | * @flags: saved IRQ-flags if the is acquired | ||
359 | * | ||
360 | * Same as refcount_dec_and_lock() above except that the spinlock is acquired | ||
361 | * with disabled interupts. | ||
362 | * | ||
363 | * Return: true and hold spinlock if able to decrement refcount to 0, false | ||
364 | * otherwise | ||
365 | */ | ||
366 | bool refcount_dec_and_lock_irqsave(refcount_t *r, spinlock_t *lock, | ||
367 | unsigned long *flags) | ||
368 | { | ||
369 | if (refcount_dec_not_one(r)) | ||
370 | return false; | ||
371 | |||
372 | spin_lock_irqsave(lock, *flags); | ||
373 | if (!refcount_dec_and_test(r)) { | ||
374 | spin_unlock_irqrestore(lock, *flags); | ||
375 | return false; | ||
376 | } | ||
377 | |||
378 | return true; | ||
379 | } | ||
380 | EXPORT_SYMBOL(refcount_dec_and_lock_irqsave); | ||