summaryrefslogtreecommitdiffstats
path: root/lib/refcount.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2018-06-26 08:07:17 +0900
committerDavid S. Miller <davem@davemloft.net>2018-06-26 08:07:17 +0900
commit9ff3b40e411c00870d1c29cd6b843fca7c4160ae (patch)
tree4d58943bf8907f5704ba004fd5383c0d7683c61f /lib/refcount.c
parent823819507095135b475a99048f0b0b6e75580fbc (diff)
parent6f0d349d922ba44e4348a17a78ea51b7135965b1 (diff)
downloadlinux-9ff3b40e411c00870d1c29cd6b843fca7c4160ae.tar.bz2
Merge ra.kernel.org:/pub/scm/linux/kernel/git/davem/net
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 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)
}
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);