1 #ifndef _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
2 #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
6 #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
9 * __set_bit - Set a bit in memory
11 * @addr: the address to start counting from
13 * Unlike set_bit(), this function is non-atomic and may be reordered.
14 * If it's called on the same region of memory simultaneously, the effect
15 * may be that only one operation succeeds.
17 static inline void __set_bit(int nr, volatile unsigned long *addr)
19 unsigned long mask = BIT_MASK(nr);
20 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
25 static inline void __clear_bit(int nr, volatile unsigned long *addr)
27 unsigned long mask = BIT_MASK(nr);
28 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
34 * __change_bit - Toggle a bit in memory
35 * @nr: the bit to change
36 * @addr: the address to start counting from
38 * Unlike change_bit(), this function is non-atomic and may be reordered.
39 * If it's called on the same region of memory simultaneously, the effect
40 * may be that only one operation succeeds.
42 static inline void __change_bit(int nr, volatile unsigned long *addr)
44 unsigned long mask = BIT_MASK(nr);
45 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
51 * __test_and_set_bit - Set a bit and return its old value
53 * @addr: Address to count from
55 * This operation is non-atomic and can be reordered.
56 * If two examples of this operation race, one can appear to succeed
57 * but actually fail. You must protect multiple accesses with a lock.
59 static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
61 unsigned long mask = BIT_MASK(nr);
62 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
63 unsigned long old = *p;
66 return (old & mask) != 0;
70 * __test_and_clear_bit - Clear a bit and return its old value
72 * @addr: Address to count from
74 * This operation is non-atomic and can be reordered.
75 * If two examples of this operation race, one can appear to succeed
76 * but actually fail. You must protect multiple accesses with a lock.
78 static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
80 unsigned long mask = BIT_MASK(nr);
81 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
82 unsigned long old = *p;
85 return (old & mask) != 0;
88 /* WARNING: non atomic and it can be reordered! */
89 static inline int __test_and_change_bit(int nr,
90 volatile unsigned long *addr)
92 unsigned long mask = BIT_MASK(nr);
93 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
94 unsigned long old = *p;
97 return (old & mask) != 0;
101 * test_bit - Determine whether a bit is set
102 * @nr: bit number to test
103 * @addr: Address to start counting from
105 static inline int test_bit(int nr, const volatile unsigned long *addr)
107 return 1UL & (addr[BITOP_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
110 #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */