summaryrefslogtreecommitdiff
path: root/include/linux/bit_spinlock.h
blob: 0e88820ad04f684a131893ce534cbc37e3e75512 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef __LINUX_BIT_SPINLOCK_H
#define __LINUX_BIT_SPINLOCK_H

#include <linux/kernel.h>
#include <linux/preempt.h>
#include <linux/atomic.h>
#include <linux/bug.h>

static inline void bit_spin_lock(int bitnum, unsigned long *addr)
{
	while (unlikely(test_and_set_bit_lock(bitnum, addr))) {
		do {
			cpu_relax();
		} while (test_bit(bitnum, addr));
	}
}

static inline int bit_spin_trylock(int bitnum, unsigned long *addr)
{
	return !test_and_set_bit_lock(bitnum, addr);
}

static inline void bit_spin_unlock(int bitnum, unsigned long *addr)
{
	BUG_ON(!test_bit(bitnum, addr));

	clear_bit_unlock(bitnum, addr);
}

static inline void __bit_spin_unlock(int bitnum, unsigned long *addr)
{
	bit_spin_unlock(bitnum, addr);
}

static inline int bit_spin_is_locked(int bitnum, unsigned long *addr)
{
	return test_bit(bitnum, addr);
}

#endif /* __LINUX_BIT_SPINLOCK_H */