https://github.com/torvalds/linux
Revision 08b8a99b2c5ea8da4d3dd55056881d12baea1e04 authored by Helge Deller on 17 September 2017, 19:17:10 UTC, committed by Helge Deller on 22 September 2017, 17:46:26 UTC
Signed-off-by: Helge Deller <deller@gmx.de>
1 parent e77900a
Raw File
Tip revision: 08b8a99b2c5ea8da4d3dd55056881d12baea1e04 authored by Helge Deller on 17 September 2017, 19:17:10 UTC
parisc: Move start_parisc() into init section
Tip revision: 08b8a99
dec_and_lock.c
#include <linux/export.h>
#include <linux/spinlock.h>
#include <linux/atomic.h>

/*
 * This is an implementation of the notion of "decrement a
 * reference count, and return locked if it decremented to zero".
 *
 * NOTE NOTE NOTE! This is _not_ equivalent to
 *
 *	if (atomic_dec_and_test(&atomic)) {
 *		spin_lock(&lock);
 *		return 1;
 *	}
 *	return 0;
 *
 * because the spin-lock and the decrement must be
 * "atomic".
 */
int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
{
	/* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
	if (atomic_add_unless(atomic, -1, 1))
		return 0;

	/* Otherwise do it the slow way */
	spin_lock(lock);
	if (atomic_dec_and_test(atomic))
		return 1;
	spin_unlock(lock);
	return 0;
}

EXPORT_SYMBOL(_atomic_dec_and_lock);
back to top