Luca's patch ported
[cbs-scheduler.git] / include / linux / bit_spinlock.h
blob864ca40df46c8b1765945513e5579ede149fa28d
1 #ifndef __LINUX_BIT_SPINLOCK_H
2 #define __LINUX_BIT_SPINLOCK_H
4 #if 0
6 /*
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.
21 preempt_disable();
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)) {
25 preempt_enable();
26 cpu_relax();
27 preempt_disable();
30 #endif
31 __acquire(bitlock);
35 * Return true if it was acquired
37 static inline int bit_spin_trylock(int bitnum, unsigned long *addr)
39 preempt_disable();
40 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
41 if (unlikely(test_and_set_bit_lock(bitnum, addr))) {
42 preempt_enable();
43 return 0;
45 #endif
46 __acquire(bitlock);
47 return 1;
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));
57 #endif
58 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
59 clear_bit_unlock(bitnum, addr);
60 #endif
61 preempt_enable();
62 __release(bitlock);
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));
74 #endif
75 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
76 __clear_bit_unlock(bitnum, addr);
77 #endif
78 preempt_enable();
79 __release(bitlock);
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();
91 #else
92 return 1;
93 #endif
96 #endif
98 #endif /* __LINUX_BIT_SPINLOCK_H */