aboutsummaryrefslogtreecommitdiff
path: root/lib/dec_and_lock.c
blob: ebbbf1a995e7ebf1b3aee9d8bdc7e1d6bf621786 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <linux/export.h>
#include <linux/spinlock.h>
#include <linux/atomic.h>

int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
{
	
	if (atomic_add_unless(atomic, -1, 1))
		return 0;

	
	spin_lock(lock);
	if (atomic_dec_and_test(atomic))
		return 1;
	spin_unlock(lock);
	return 0;
}

EXPORT_SYMBOL(_atomic_dec_and_lock);