summaryrefslogtreecommitdiff
path: root/lib/refcount.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2018-07-17 09:27:43 +0200
committerIngo Molnar <mingo@kernel.org>2018-07-17 09:27:43 +0200
commit52b544bd386688177c41d53e748111c29d0ccc98 (patch)
treec2083582176e773084364af93cc44e0f94b6cde8 /lib/refcount.c
parentafed7bcf9487bb28e2e2b016a195085c07416c0b (diff)
parent9d3cce1e8b8561fed5f383d22a4d6949db4eadbe (diff)
Merge tag 'v4.18-rc5' into locking/core, to pick up fixes
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'lib/refcount.c')
-rw-r--r--lib/refcount.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/refcount.c b/lib/refcount.c
index 5c4aaefc0682..ebcf8cd49e05 100644
--- a/lib/refcount.c
+++ b/lib/refcount.c
@@ -349,3 +349,31 @@ bool refcount_dec_and_lock(refcount_t *r, spinlock_t *lock)
}
EXPORT_SYMBOL(refcount_dec_and_lock);
+/**
+ * refcount_dec_and_lock_irqsave - return holding spinlock with disabled
+ * interrupts if able to decrement refcount to 0
+ * @r: the refcount
+ * @lock: the spinlock to be locked
+ * @flags: saved IRQ-flags if the is acquired
+ *
+ * Same as refcount_dec_and_lock() above except that the spinlock is acquired
+ * with disabled interupts.
+ *
+ * Return: true and hold spinlock if able to decrement refcount to 0, false
+ * otherwise
+ */
+bool refcount_dec_and_lock_irqsave(refcount_t *r, spinlock_t *lock,
+ unsigned long *flags)
+{
+ if (refcount_dec_not_one(r))
+ return false;
+
+ spin_lock_irqsave(lock, *flags);
+ if (!refcount_dec_and_test(r)) {
+ spin_unlock_irqrestore(lock, *flags);
+ return false;
+ }
+
+ return true;
+}
+EXPORT_SYMBOL(refcount_dec_and_lock_irqsave);