refcount.c (c95baf12f5077419db01313ab61c2aac007d40cd) refcount.c (9dbbc3b9d09d6deba9f3b9e1d5b355032ed46a75)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Out-of-line refcount functions.
4 */
5
6#include <linux/mutex.h>
7#include <linux/refcount.h>
8#include <linux/spinlock.h>

--- 150 unchanged lines hidden (view full) ---

159/**
160 * refcount_dec_and_lock_irqsave - return holding spinlock with disabled
161 * interrupts if able to decrement refcount to 0
162 * @r: the refcount
163 * @lock: the spinlock to be locked
164 * @flags: saved IRQ-flags if the is acquired
165 *
166 * Same as refcount_dec_and_lock() above except that the spinlock is acquired
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Out-of-line refcount functions.
4 */
5
6#include <linux/mutex.h>
7#include <linux/refcount.h>
8#include <linux/spinlock.h>

--- 150 unchanged lines hidden (view full) ---

159/**
160 * refcount_dec_and_lock_irqsave - return holding spinlock with disabled
161 * interrupts if able to decrement refcount to 0
162 * @r: the refcount
163 * @lock: the spinlock to be locked
164 * @flags: saved IRQ-flags if the is acquired
165 *
166 * Same as refcount_dec_and_lock() above except that the spinlock is acquired
167 * with disabled interupts.
167 * with disabled interrupts.
168 *
169 * Return: true and hold spinlock if able to decrement refcount to 0, false
170 * otherwise
171 */
172bool refcount_dec_and_lock_irqsave(refcount_t *r, spinlock_t *lock,
173 unsigned long *flags)
174{
175 if (refcount_dec_not_one(r))
176 return false;
177
178 spin_lock_irqsave(lock, *flags);
179 if (!refcount_dec_and_test(r)) {
180 spin_unlock_irqrestore(lock, *flags);
181 return false;
182 }
183
184 return true;
185}
186EXPORT_SYMBOL(refcount_dec_and_lock_irqsave);
168 *
169 * Return: true and hold spinlock if able to decrement refcount to 0, false
170 * otherwise
171 */
172bool refcount_dec_and_lock_irqsave(refcount_t *r, spinlock_t *lock,
173 unsigned long *flags)
174{
175 if (refcount_dec_not_one(r))
176 return false;
177
178 spin_lock_irqsave(lock, *flags);
179 if (!refcount_dec_and_test(r)) {
180 spin_unlock_irqrestore(lock, *flags);
181 return false;
182 }
183
184 return true;
185}
186EXPORT_SYMBOL(refcount_dec_and_lock_irqsave);