1 #ifndef _LINUX_ATOMIC_H
2 #define _LINUX_ATOMIC_H
4 #include <linux/types.h>
14 #define ATOMIC_INIT(i) (i)
17 * atomic_read - read atomic variable
18 * @v: pointer of type atomic_t
20 * Atomically reads the value of @v. Note that the guaranteed
21 * useful range of an atomic_t is only 24 bits.
23 #define atomic_read(v) ((v)->counter)
26 * atomic_set - set atomic variable
27 * @v: pointer of type atomic_t
30 * Atomically sets the value of @v to @i. Note that the guaranteed
31 * useful range of an atomic_t is only 24 bits.
33 #define atomic_set(v,i) InterlockedExchange((PLONG)(&(v)->counter), (LONG)(i))
36 * atomic_add - add integer to atomic variable
37 * @i: integer value to add
38 * @v: pointer of type atomic_t
40 * Atomically adds @i to @v. Note that the guaranteed useful range
41 * of an atomic_t is only 24 bits.
43 static inline void atomic_add(int volatile i
, atomic_t
volatile *v
)
45 InterlockedExchangeAdd((PLONG
)(&v
->counter
), (LONG
) i
);
49 * atomic_sub - subtract the atomic variable
50 * @i: integer value to subtract
51 * @v: pointer of type atomic_t
53 * Atomically subtracts @i from @v. Note that the guaranteed
54 * useful range of an atomic_t is only 24 bits.
56 static inline void atomic_sub(int volatile i
, atomic_t
volatile *v
)
58 InterlockedExchangeAdd((PLONG
)(&v
->counter
), (LONG
) (-1*i
));
62 * atomic_sub_and_test - subtract value from variable and test result
63 * @i: integer value to subtract
64 * @v: pointer of type atomic_t
66 * Atomically subtracts @i from @v and returns
67 * true if the result is zero, or false for all
68 * other cases. Note that the guaranteed
69 * useful range of an atomic_t is only 24 bits.
71 static inline int atomic_sub_and_test(int volatile i
, atomic_t
volatile *v
)
80 } while ( InterlockedCompareExchange(
81 (PLONG
) (&v
->counter
),
83 (LONG
) counter
) != counter
);
89 * atomic_inc - increment atomic variable
90 * @v: pointer of type atomic_t
92 * Atomically increments @v by 1. Note that the guaranteed
93 * useful range of an atomic_t is only 24 bits.
95 static inline void atomic_inc(atomic_t
volatile *v
)
97 InterlockedIncrement((PLONG
)(&v
->counter
));
101 * atomic_dec - decrement atomic variable
102 * @v: pointer of type atomic_t
104 * Atomically decrements @v by 1. Note that the guaranteed
105 * useful range of an atomic_t is only 24 bits.
107 static inline void atomic_dec(atomic_t
volatile *v
)
109 InterlockedDecrement((PLONG
)(&v
->counter
));
113 * atomic_dec_and_test - decrement and test
114 * @v: pointer of type atomic_t
116 * Atomically decrements @v by 1 and
117 * returns true if the result is 0, or false for all other
118 * cases. Note that the guaranteed
119 * useful range of an atomic_t is only 24 bits.
121 static inline int atomic_dec_and_test(atomic_t
volatile *v
)
123 return (0 == InterlockedDecrement((PLONG
)(&v
->counter
)));
127 * atomic_inc_and_test - increment and test
128 * @v: pointer of type atomic_t
130 * Atomically increments @v by 1
131 * and returns true if the result is zero, or false for all
132 * other cases. Note that the guaranteed
133 * useful range of an atomic_t is only 24 bits.
135 static inline int atomic_inc_and_test(atomic_t
volatile *v
)
137 return (0 == InterlockedIncrement((PLONG
)(&v
->counter
)));
141 * atomic_add_negative - add and test if negative
142 * @v: pointer of type atomic_t
143 * @i: integer value to add
145 * Atomically adds @i to @v and returns true
146 * if the result is negative, or false when
147 * result is greater than or equal to zero. Note that the guaranteed
148 * useful range of an atomic_t is only 24 bits.
150 static inline int atomic_add_negative(int volatile i
, atomic_t
volatile *v
)
152 return (InterlockedExchangeAdd((PLONG
)(&v
->counter
), (LONG
) i
) + i
);
155 #endif /* LINUX_ATOMIC_H */