H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_ATOMIC_32_H |
| 2 | #define _ASM_X86_ATOMIC_32_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/compiler.h> |
Matthew Wilcox | ea435467 | 2009-01-06 14:40:39 -0800 | [diff] [blame] | 5 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <asm/processor.h> |
Jeff Dike | a436ed9 | 2007-05-08 00:35:02 -0700 | [diff] [blame] | 7 | #include <asm/cmpxchg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 9 | /* |
| 10 | * Atomic operations that C can't guarantee us. Useful for |
| 11 | * resource counting etc.. |
| 12 | */ |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #define ATOMIC_INIT(i) { (i) } |
| 15 | |
| 16 | /** |
| 17 | * atomic_read - read atomic variable |
| 18 | * @v: pointer of type atomic_t |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 19 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * Atomically reads the value of @v. |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 21 | */ |
Ingo Molnar | 3217120 | 2009-07-03 13:06:01 +0200 | [diff] [blame^] | 22 | static inline int atomic_read(const atomic_t *v) |
| 23 | { |
| 24 | return v->counter; |
| 25 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * atomic_set - set atomic variable |
| 29 | * @v: pointer of type atomic_t |
| 30 | * @i: required value |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 31 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | * Atomically sets the value of @v to @i. |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 33 | */ |
| 34 | #define atomic_set(v, i) (((v)->counter) = (i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * atomic_add - add integer to atomic variable |
| 38 | * @i: integer value to add |
| 39 | * @v: pointer of type atomic_t |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 40 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | * Atomically adds @i to @v. |
| 42 | */ |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 43 | static inline void atomic_add(int i, atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 45 | asm volatile(LOCK_PREFIX "addl %1,%0" |
| 46 | : "+m" (v->counter) |
| 47 | : "ir" (i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /** |
Robert P. J. Day | cc38682 | 2007-05-08 00:35:08 -0700 | [diff] [blame] | 51 | * atomic_sub - subtract integer from atomic variable |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | * @i: integer value to subtract |
| 53 | * @v: pointer of type atomic_t |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 54 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * Atomically subtracts @i from @v. |
| 56 | */ |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 57 | static inline void atomic_sub(int i, atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 59 | asm volatile(LOCK_PREFIX "subl %1,%0" |
| 60 | : "+m" (v->counter) |
| 61 | : "ir" (i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /** |
| 65 | * atomic_sub_and_test - subtract value from variable and test result |
| 66 | * @i: integer value to subtract |
| 67 | * @v: pointer of type atomic_t |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 68 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | * Atomically subtracts @i from @v and returns |
| 70 | * true if the result is zero, or false for all |
| 71 | * other cases. |
| 72 | */ |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 73 | static inline int atomic_sub_and_test(int i, atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
| 75 | unsigned char c; |
| 76 | |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 77 | asm volatile(LOCK_PREFIX "subl %2,%0; sete %1" |
| 78 | : "+m" (v->counter), "=qm" (c) |
| 79 | : "ir" (i) : "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | return c; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * atomic_inc - increment atomic variable |
| 85 | * @v: pointer of type atomic_t |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 86 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | * Atomically increments @v by 1. |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 88 | */ |
| 89 | static inline void atomic_inc(atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 91 | asm volatile(LOCK_PREFIX "incl %0" |
| 92 | : "+m" (v->counter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
| 96 | * atomic_dec - decrement atomic variable |
| 97 | * @v: pointer of type atomic_t |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 98 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | * Atomically decrements @v by 1. |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 100 | */ |
| 101 | static inline void atomic_dec(atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 103 | asm volatile(LOCK_PREFIX "decl %0" |
| 104 | : "+m" (v->counter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** |
| 108 | * atomic_dec_and_test - decrement and test |
| 109 | * @v: pointer of type atomic_t |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 110 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | * Atomically decrements @v by 1 and |
| 112 | * returns true if the result is 0, or false for all other |
| 113 | * cases. |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 114 | */ |
| 115 | static inline int atomic_dec_and_test(atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
| 117 | unsigned char c; |
| 118 | |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 119 | asm volatile(LOCK_PREFIX "decl %0; sete %1" |
| 120 | : "+m" (v->counter), "=qm" (c) |
| 121 | : : "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | return c != 0; |
| 123 | } |
| 124 | |
| 125 | /** |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 126 | * atomic_inc_and_test - increment and test |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | * @v: pointer of type atomic_t |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 128 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | * Atomically increments @v by 1 |
| 130 | * and returns true if the result is zero, or false for all |
| 131 | * other cases. |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 132 | */ |
| 133 | static inline int atomic_inc_and_test(atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
| 135 | unsigned char c; |
| 136 | |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 137 | asm volatile(LOCK_PREFIX "incl %0; sete %1" |
| 138 | : "+m" (v->counter), "=qm" (c) |
| 139 | : : "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | return c != 0; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * atomic_add_negative - add and test if negative |
| 145 | * @v: pointer of type atomic_t |
| 146 | * @i: integer value to add |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 147 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | * Atomically adds @i to @v and returns true |
| 149 | * if the result is negative, or false when |
| 150 | * result is greater than or equal to zero. |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 151 | */ |
| 152 | static inline int atomic_add_negative(int i, atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
| 154 | unsigned char c; |
| 155 | |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 156 | asm volatile(LOCK_PREFIX "addl %2,%0; sets %1" |
| 157 | : "+m" (v->counter), "=qm" (c) |
| 158 | : "ir" (i) : "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | return c; |
| 160 | } |
| 161 | |
| 162 | /** |
Robert P. J. Day | cc38682 | 2007-05-08 00:35:08 -0700 | [diff] [blame] | 163 | * atomic_add_return - add integer and return |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | * @v: pointer of type atomic_t |
| 165 | * @i: integer value to add |
| 166 | * |
| 167 | * Atomically adds @i to @v and returns @i + @v |
| 168 | */ |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 169 | static inline int atomic_add_return(int i, atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
| 171 | int __i; |
| 172 | #ifdef CONFIG_M386 |
lepton | 1bb858f | 2006-04-18 22:21:10 -0700 | [diff] [blame] | 173 | unsigned long flags; |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 174 | if (unlikely(boot_cpu_data.x86 <= 3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | goto no_xadd; |
| 176 | #endif |
| 177 | /* Modern 486+ processor */ |
| 178 | __i = i; |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 179 | asm volatile(LOCK_PREFIX "xaddl %0, %1" |
| 180 | : "+r" (i), "+m" (v->counter) |
| 181 | : : "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | return i + __i; |
| 183 | |
| 184 | #ifdef CONFIG_M386 |
| 185 | no_xadd: /* Legacy 386 processor */ |
lepton | 1bb858f | 2006-04-18 22:21:10 -0700 | [diff] [blame] | 186 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | __i = atomic_read(v); |
| 188 | atomic_set(v, i + __i); |
lepton | 1bb858f | 2006-04-18 22:21:10 -0700 | [diff] [blame] | 189 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | return i + __i; |
| 191 | #endif |
| 192 | } |
| 193 | |
Robert P. J. Day | cc38682 | 2007-05-08 00:35:08 -0700 | [diff] [blame] | 194 | /** |
| 195 | * atomic_sub_return - subtract integer and return |
| 196 | * @v: pointer of type atomic_t |
| 197 | * @i: integer value to subtract |
| 198 | * |
| 199 | * Atomically subtracts @i from @v and returns @v - @i |
| 200 | */ |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 201 | static inline int atomic_sub_return(int i, atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 203 | return atomic_add_return(-i, v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Mathieu Desnoyers | e656e24 | 2007-05-08 00:34:20 -0700 | [diff] [blame] | 206 | #define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new))) |
| 207 | #define atomic_xchg(v, new) (xchg(&((v)->counter), (new))) |
Nick Piggin | 4a6dae6 | 2005-11-13 16:07:24 -0800 | [diff] [blame] | 208 | |
Nick Piggin | 8426e1f | 2005-11-13 16:07:25 -0800 | [diff] [blame] | 209 | /** |
Robert P. J. Day | 72fd4a3 | 2007-02-10 01:45:59 -0800 | [diff] [blame] | 210 | * atomic_add_unless - add unless the number is already a given value |
Nick Piggin | 8426e1f | 2005-11-13 16:07:25 -0800 | [diff] [blame] | 211 | * @v: pointer of type atomic_t |
| 212 | * @a: the amount to add to v... |
| 213 | * @u: ...unless v is equal to u. |
| 214 | * |
Robert P. J. Day | 72fd4a3 | 2007-02-10 01:45:59 -0800 | [diff] [blame] | 215 | * Atomically adds @a to @v, so long as @v was not already @u. |
Nick Piggin | 8426e1f | 2005-11-13 16:07:25 -0800 | [diff] [blame] | 216 | * Returns non-zero if @v was not @u, and zero otherwise. |
| 217 | */ |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 218 | static inline int atomic_add_unless(atomic_t *v, int a, int u) |
Mathieu Desnoyers | 2856f5e | 2007-05-08 00:34:38 -0700 | [diff] [blame] | 219 | { |
| 220 | int c, old; |
| 221 | c = atomic_read(v); |
| 222 | for (;;) { |
| 223 | if (unlikely(c == (u))) |
| 224 | break; |
| 225 | old = atomic_cmpxchg((v), c, c + (a)); |
| 226 | if (likely(old == c)) |
| 227 | break; |
| 228 | c = old; |
| 229 | } |
| 230 | return c != (u); |
| 231 | } |
| 232 | |
Nick Piggin | 8426e1f | 2005-11-13 16:07:25 -0800 | [diff] [blame] | 233 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) |
| 234 | |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 235 | #define atomic_inc_return(v) (atomic_add_return(1, v)) |
| 236 | #define atomic_dec_return(v) (atomic_sub_return(1, v)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | /* These are x86-specific, used by some header files */ |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 239 | #define atomic_clear_mask(mask, addr) \ |
| 240 | asm volatile(LOCK_PREFIX "andl %0,%1" \ |
| 241 | : : "r" (~(mask)), "m" (*(addr)) : "memory") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Joe Perches | 78ff12e | 2008-03-23 01:01:41 -0700 | [diff] [blame] | 243 | #define atomic_set_mask(mask, addr) \ |
| 244 | asm volatile(LOCK_PREFIX "orl %0,%1" \ |
| 245 | : : "r" (mask), "m" (*(addr)) : "memory") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | /* Atomic operations are already serializing on x86 */ |
| 248 | #define smp_mb__before_atomic_dec() barrier() |
| 249 | #define smp_mb__after_atomic_dec() barrier() |
| 250 | #define smp_mb__before_atomic_inc() barrier() |
| 251 | #define smp_mb__after_atomic_inc() barrier() |
| 252 | |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 253 | /* An 64bit atomic type */ |
| 254 | |
| 255 | typedef struct { |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 256 | u64 __aligned(8) counter; |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 257 | } atomic64_t; |
| 258 | |
| 259 | #define ATOMIC64_INIT(val) { (val) } |
| 260 | |
| 261 | /** |
| 262 | * atomic64_read - read atomic64 variable |
Randy Dunlap | 46e4432 | 2009-06-13 20:00:54 -0700 | [diff] [blame] | 263 | * @ptr: pointer of type atomic64_t |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 264 | * |
| 265 | * Atomically reads the value of @v. |
| 266 | * Doesn't imply a read memory barrier. |
| 267 | */ |
| 268 | #define __atomic64_read(ptr) ((ptr)->counter) |
| 269 | |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 270 | extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 271 | |
| 272 | /** |
Ingo Molnar | 98c2aaf | 2009-04-07 11:30:17 +0200 | [diff] [blame] | 273 | * atomic64_xchg - xchg atomic64 variable |
| 274 | * @ptr: pointer to type atomic64_t |
| 275 | * @new_val: value to assign |
Ingo Molnar | 98c2aaf | 2009-04-07 11:30:17 +0200 | [diff] [blame] | 276 | * |
| 277 | * Atomically xchgs the value of @ptr to @new_val and returns |
| 278 | * the old value. |
| 279 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 280 | extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val); |
Ingo Molnar | 98c2aaf | 2009-04-07 11:30:17 +0200 | [diff] [blame] | 281 | |
| 282 | /** |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 283 | * atomic64_set - set atomic64 variable |
| 284 | * @ptr: pointer to type atomic64_t |
| 285 | * @new_val: value to assign |
| 286 | * |
| 287 | * Atomically sets the value of @ptr to @new_val. |
| 288 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 289 | extern void atomic64_set(atomic64_t *ptr, u64 new_val); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 290 | |
| 291 | /** |
| 292 | * atomic64_read - read atomic64 variable |
| 293 | * @ptr: pointer to type atomic64_t |
| 294 | * |
| 295 | * Atomically reads the value of @ptr and returns it. |
| 296 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 297 | extern u64 atomic64_read(atomic64_t *ptr); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 298 | |
| 299 | /** |
| 300 | * atomic64_add_return - add and return |
| 301 | * @delta: integer value to add |
| 302 | * @ptr: pointer to type atomic64_t |
| 303 | * |
| 304 | * Atomically adds @delta to @ptr and returns @delta + *@ptr |
| 305 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 306 | extern u64 atomic64_add_return(u64 delta, atomic64_t *ptr); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 307 | |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 308 | /* |
| 309 | * Other variants with different arithmetic operators: |
| 310 | */ |
| 311 | extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr); |
| 312 | extern u64 atomic64_inc_return(atomic64_t *ptr); |
| 313 | extern u64 atomic64_dec_return(atomic64_t *ptr); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 314 | |
| 315 | /** |
| 316 | * atomic64_add - add integer to atomic64 variable |
| 317 | * @delta: integer value to add |
| 318 | * @ptr: pointer to type atomic64_t |
| 319 | * |
| 320 | * Atomically adds @delta to @ptr. |
| 321 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 322 | extern void atomic64_add(u64 delta, atomic64_t *ptr); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 323 | |
| 324 | /** |
| 325 | * atomic64_sub - subtract the atomic64 variable |
| 326 | * @delta: integer value to subtract |
| 327 | * @ptr: pointer to type atomic64_t |
| 328 | * |
| 329 | * Atomically subtracts @delta from @ptr. |
| 330 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 331 | extern void atomic64_sub(u64 delta, atomic64_t *ptr); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 332 | |
| 333 | /** |
| 334 | * atomic64_sub_and_test - subtract value from variable and test result |
| 335 | * @delta: integer value to subtract |
| 336 | * @ptr: pointer to type atomic64_t |
| 337 | * |
| 338 | * Atomically subtracts @delta from @ptr and returns |
| 339 | * true if the result is zero, or false for all |
| 340 | * other cases. |
| 341 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 342 | extern int atomic64_sub_and_test(u64 delta, atomic64_t *ptr); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 343 | |
| 344 | /** |
| 345 | * atomic64_inc - increment atomic64 variable |
| 346 | * @ptr: pointer to type atomic64_t |
| 347 | * |
| 348 | * Atomically increments @ptr by 1. |
| 349 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 350 | extern void atomic64_inc(atomic64_t *ptr); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 351 | |
| 352 | /** |
| 353 | * atomic64_dec - decrement atomic64 variable |
| 354 | * @ptr: pointer to type atomic64_t |
| 355 | * |
| 356 | * Atomically decrements @ptr by 1. |
| 357 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 358 | extern void atomic64_dec(atomic64_t *ptr); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 359 | |
| 360 | /** |
| 361 | * atomic64_dec_and_test - decrement and test |
| 362 | * @ptr: pointer to type atomic64_t |
| 363 | * |
| 364 | * Atomically decrements @ptr by 1 and |
| 365 | * returns true if the result is 0, or false for all other |
| 366 | * cases. |
| 367 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 368 | extern int atomic64_dec_and_test(atomic64_t *ptr); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 369 | |
| 370 | /** |
| 371 | * atomic64_inc_and_test - increment and test |
| 372 | * @ptr: pointer to type atomic64_t |
| 373 | * |
| 374 | * Atomically increments @ptr by 1 |
| 375 | * and returns true if the result is zero, or false for all |
| 376 | * other cases. |
| 377 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 378 | extern int atomic64_inc_and_test(atomic64_t *ptr); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 379 | |
| 380 | /** |
| 381 | * atomic64_add_negative - add and test if negative |
| 382 | * @delta: integer value to add |
| 383 | * @ptr: pointer to type atomic64_t |
| 384 | * |
| 385 | * Atomically adds @delta to @ptr and returns true |
| 386 | * if the result is negative, or false when |
| 387 | * result is greater than or equal to zero. |
| 388 | */ |
Ingo Molnar | b7882b7 | 2009-07-03 13:26:39 +0200 | [diff] [blame] | 389 | extern int atomic64_add_negative(u64 delta, atomic64_t *ptr); |
Ingo Molnar | 9b194e8 | 2008-12-14 20:22:35 +0100 | [diff] [blame] | 390 | |
Arnd Bergmann | 72099ed | 2009-05-13 22:56:29 +0000 | [diff] [blame] | 391 | #include <asm-generic/atomic-long.h> |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 392 | #endif /* _ASM_X86_ATOMIC_32_H */ |