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 #define PLATFORM__SET_BIT
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) + BIT_WORD(nr);
33 #define PLATFORM__CLEAR_BIT
36 * __change_bit - Toggle a bit in memory
37 * @nr: the bit to change
38 * @addr: the address to start counting from
40 * Unlike change_bit(), this function is non-atomic and may be reordered.
41 * If it's called on the same region of memory simultaneously, the effect
42 * may be that only one operation succeeds.
44 static inline void __change_bit(int nr, volatile unsigned long *addr)
46 unsigned long mask = BIT_MASK(nr);
47 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
53 * __test_and_set_bit - Set a bit and return its old value
55 * @addr: Address to count from
57 * This operation is non-atomic and can be reordered.
58 * If two examples of this operation race, one can appear to succeed
59 * but actually fail. You must protect multiple accesses with a lock.
61 static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
63 unsigned long mask = BIT_MASK(nr);
64 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
65 unsigned long old = *p;
68 return (old & mask) != 0;
72 * __test_and_clear_bit - Clear a bit and return its old value
74 * @addr: Address to count from
76 * This operation is non-atomic and can be reordered.
77 * If two examples of this operation race, one can appear to succeed
78 * but actually fail. You must protect multiple accesses with a lock.
80 static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
82 unsigned long mask = BIT_MASK(nr);
83 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
84 unsigned long old = *p;
87 return (old & mask) != 0;
90 /* WARNING: non atomic and it can be reordered! */
91 static inline int __test_and_change_bit(int nr,
92 volatile unsigned long *addr)
94 unsigned long mask = BIT_MASK(nr);
95 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
96 unsigned long old = *p;
99 return (old & mask) != 0;
103 * test_bit - Determine whether a bit is set
104 * @nr: bit number to test
105 * @addr: Address to start counting from
107 static inline int test_bit(int nr, const volatile unsigned long *addr)
109 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
112 #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */