Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
non-atomic.h
Go to the documentation of this file.
1 #ifndef _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
2 #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
3 
4 #include <asm/types.h>
5 
15 static inline void __set_bit(int nr, volatile unsigned long *addr)
16 {
17  unsigned long mask = BIT_MASK(nr);
18  unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
19 
20  *p |= mask;
21 }
22 
23 static inline void __clear_bit(int nr, volatile unsigned long *addr)
24 {
25  unsigned long mask = BIT_MASK(nr);
26  unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
27 
28  *p &= ~mask;
29 }
30 
40 static inline void __change_bit(int nr, volatile unsigned long *addr)
41 {
42  unsigned long mask = BIT_MASK(nr);
43  unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
44 
45  *p ^= mask;
46 }
47 
57 static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
58 {
59  unsigned long mask = BIT_MASK(nr);
60  unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
61  unsigned long old = *p;
62 
63  *p = old | mask;
64  return (old & mask) != 0;
65 }
66 
76 static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
77 {
78  unsigned long mask = BIT_MASK(nr);
79  unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
80  unsigned long old = *p;
81 
82  *p = old & ~mask;
83  return (old & mask) != 0;
84 }
85 
86 /* WARNING: non atomic and it can be reordered! */
87 static inline int __test_and_change_bit(int nr,
88  volatile unsigned long *addr)
89 {
90  unsigned long mask = BIT_MASK(nr);
91  unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
92  unsigned long old = *p;
93 
94  *p = old ^ mask;
95  return (old & mask) != 0;
96 }
97 
103 static inline int test_bit(int nr, const volatile unsigned long *addr)
104 {
105  return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
106 }
107 
108 #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */