1 #ifndef _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
2 #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
7 * __set_bit - Set a bit in memory
9 * @addr: the address to start counting from
11 * Unlike set_bit(), this function is non-atomic and may be reordered.
12 * If it's called on the same region of memory simultaneously, the effect
13 * may be that only one operation succeeds.
15 static inline void __set_bit(int nr, volatile unsigned long *addr)
17 unsigned long mask = BIT_MASK(nr);
18 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
23 static inline void __clear_bit(int nr, volatile unsigned long *addr)
25 unsigned long mask = BIT_MASK(nr);
26 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
32 * __change_bit - Toggle a bit in memory
33 * @nr: the bit to change
34 * @addr: the address to start counting from
36 * Unlike change_bit(), this function is non-atomic and may be reordered.
37 * If it's called on the same region of memory simultaneously, the effect
38 * may be that only one operation succeeds.
40 static inline void __change_bit(int nr, volatile unsigned long *addr)
42 unsigned long mask = BIT_MASK(nr);
43 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
49 * __test_and_set_bit - Set a bit and return its old value
51 * @addr: Address to count from
53 * This operation is non-atomic and can be reordered.
54 * If two examples of this operation race, one can appear to succeed
55 * but actually fail. You must protect multiple accesses with a lock.
57 static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
59 unsigned long mask = BIT_MASK(nr);
60 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
61 unsigned long old = *p;
64 return (old & mask) != 0;
68 * __test_and_clear_bit - Clear a bit and return its old value
70 * @addr: Address to count from
72 * This operation is non-atomic and can be reordered.
73 * If two examples of this operation race, one can appear to succeed
74 * but actually fail. You must protect multiple accesses with a lock.
76 static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
78 unsigned long mask = BIT_MASK(nr);
79 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
80 unsigned long old = *p;
83 return (old & mask) != 0;
86 /* WARNING: non atomic and it can be reordered! */
87 static inline int __test_and_change_bit(int nr,
88 volatile unsigned long *addr)
90 unsigned long mask = BIT_MASK(nr);
91 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
92 unsigned long old = *p;
95 return (old & mask) != 0;
99 * test_bit - Determine whether a bit is set
100 * @nr: bit number to test
101 * @addr: Address to start counting from
103 static inline int test_bit(int nr, const volatile unsigned long *addr)
105 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
108 #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */