1 #ifndef __LINUX_BIT_SPINLOCK_H
2 #define __LINUX_BIT_SPINLOCK_H
7 * bit-based spin_lock()
9 * Don't use this unless you really need to: spin_lock() and spin_unlock()
10 * are significantly faster.
12 static inline void bit_spin_lock(int bitnum
, unsigned long *addr
)
15 * Assuming the lock is uncontended, this never enters
16 * the body of the outer loop. If it is contended, then
17 * within the inner loop a non-atomic test is used to
18 * busywait with less bus contention for a good time to
19 * attempt to acquire the lock bit.
22 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
23 while (unlikely(test_and_set_bit_lock(bitnum
, addr
))) {
24 while (test_bit(bitnum
, addr
)) {
35 * Return true if it was acquired
37 static inline int bit_spin_trylock(int bitnum
, unsigned long *addr
)
40 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
41 if (unlikely(test_and_set_bit_lock(bitnum
, addr
))) {
51 * bit-based spin_unlock()
53 static inline void bit_spin_unlock(int bitnum
, unsigned long *addr
)
55 #ifdef CONFIG_DEBUG_SPINLOCK
56 BUG_ON(!test_bit(bitnum
, addr
));
58 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
59 clear_bit_unlock(bitnum
, addr
);
66 * bit-based spin_unlock()
67 * non-atomic version, which can be used eg. if the bit lock itself is
68 * protecting the rest of the flags in the word.
70 static inline void __bit_spin_unlock(int bitnum
, unsigned long *addr
)
72 #ifdef CONFIG_DEBUG_SPINLOCK
73 BUG_ON(!test_bit(bitnum
, addr
));
75 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
76 __clear_bit_unlock(bitnum
, addr
);
83 * Return true if the lock is held.
85 static inline int bit_spin_is_locked(int bitnum
, unsigned long *addr
)
87 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
88 return test_bit(bitnum
, addr
);
89 #elif defined CONFIG_PREEMPT
90 return preempt_count();
98 #endif /* __LINUX_BIT_SPINLOCK_H */