Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ARCH_S390_ATOMIC__ |
| 2 | #define __ARCH_S390_ATOMIC__ |
| 3 | |
Heiko Carstens | 1275105 | 2009-09-11 10:28:34 +0200 | [diff] [blame] | 4 | /* |
| 5 | * Copyright 1999,2009 IBM Corp. |
| 6 | * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>, |
| 7 | * Denis Joseph Barrow, |
| 8 | * Arnd Bergmann <arndb@de.ibm.com>, |
| 9 | * |
| 10 | * Atomic operations that C can't guarantee us. |
| 11 | * Useful for resource counting etc. |
| 12 | * s390 uses 'Compare And Swap' for atomicity in SMP enviroment. |
| 13 | * |
| 14 | */ |
| 15 | |
Dave Jones | 5bd1db6 | 2006-04-10 22:53:51 -0700 | [diff] [blame] | 16 | #include <linux/compiler.h> |
Matthew Wilcox | ea435467 | 2009-01-06 14:40:39 -0800 | [diff] [blame] | 17 | #include <linux/types.h> |
Dave Jones | 5bd1db6 | 2006-04-10 22:53:51 -0700 | [diff] [blame] | 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #define ATOMIC_INIT(i) { (i) } |
| 20 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 21 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2) |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #define __CS_LOOP(ptr, op_val, op_string) ({ \ |
Martin Schwidefsky | 3947517 | 2009-12-07 12:52:05 +0100 | [diff] [blame^] | 24 | int old_val, new_val; \ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 25 | asm volatile( \ |
| 26 | " l %0,%2\n" \ |
| 27 | "0: lr %1,%0\n" \ |
| 28 | op_string " %1,%3\n" \ |
| 29 | " cs %0,%1,%2\n" \ |
| 30 | " jl 0b" \ |
| 31 | : "=&d" (old_val), "=&d" (new_val), \ |
| 32 | "=Q" (((atomic_t *)(ptr))->counter) \ |
| 33 | : "d" (op_val), "Q" (((atomic_t *)(ptr))->counter) \ |
| 34 | : "cc", "memory"); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | new_val; \ |
| 36 | }) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 37 | |
| 38 | #else /* __GNUC__ */ |
| 39 | |
| 40 | #define __CS_LOOP(ptr, op_val, op_string) ({ \ |
Martin Schwidefsky | 3947517 | 2009-12-07 12:52:05 +0100 | [diff] [blame^] | 41 | int old_val, new_val; \ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 42 | asm volatile( \ |
| 43 | " l %0,0(%3)\n" \ |
| 44 | "0: lr %1,%0\n" \ |
| 45 | op_string " %1,%4\n" \ |
| 46 | " cs %0,%1,0(%3)\n" \ |
| 47 | " jl 0b" \ |
| 48 | : "=&d" (old_val), "=&d" (new_val), \ |
| 49 | "=m" (((atomic_t *)(ptr))->counter) \ |
| 50 | : "a" (ptr), "d" (op_val), \ |
| 51 | "m" (((atomic_t *)(ptr))->counter) \ |
| 52 | : "cc", "memory"); \ |
| 53 | new_val; \ |
| 54 | }) |
| 55 | |
| 56 | #endif /* __GNUC__ */ |
| 57 | |
Heiko Carstens | c51b962 | 2007-08-22 13:51:45 +0200 | [diff] [blame] | 58 | static inline int atomic_read(const atomic_t *v) |
| 59 | { |
| 60 | barrier(); |
| 61 | return v->counter; |
| 62 | } |
| 63 | |
| 64 | static inline void atomic_set(atomic_t *v, int i) |
| 65 | { |
| 66 | v->counter = i; |
| 67 | barrier(); |
| 68 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 70 | static inline int atomic_add_return(int i, atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
| 72 | return __CS_LOOP(v, i, "ar"); |
| 73 | } |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 74 | #define atomic_add(_i, _v) atomic_add_return(_i, _v) |
| 75 | #define atomic_add_negative(_i, _v) (atomic_add_return(_i, _v) < 0) |
| 76 | #define atomic_inc(_v) atomic_add_return(1, _v) |
| 77 | #define atomic_inc_return(_v) atomic_add_return(1, _v) |
| 78 | #define atomic_inc_and_test(_v) (atomic_add_return(1, _v) == 0) |
| 79 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 80 | static inline int atomic_sub_return(int i, atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | return __CS_LOOP(v, i, "sr"); |
| 83 | } |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 84 | #define atomic_sub(_i, _v) atomic_sub_return(_i, _v) |
| 85 | #define atomic_sub_and_test(_i, _v) (atomic_sub_return(_i, _v) == 0) |
| 86 | #define atomic_dec(_v) atomic_sub_return(1, _v) |
| 87 | #define atomic_dec_return(_v) atomic_sub_return(1, _v) |
| 88 | #define atomic_dec_and_test(_v) (atomic_sub_return(1, _v) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 90 | static inline void atomic_clear_mask(unsigned long mask, atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 92 | __CS_LOOP(v, ~mask, "nr"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 94 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 95 | static inline void atomic_set_mask(unsigned long mask, atomic_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 97 | __CS_LOOP(v, mask, "or"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 99 | |
Ingo Molnar | ffbf670 | 2006-01-09 15:59:17 -0800 | [diff] [blame] | 100 | #define atomic_xchg(v, new) (xchg(&((v)->counter), new)) |
| 101 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 102 | static inline int atomic_cmpxchg(atomic_t *v, int old, int new) |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 103 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 104 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2) |
| 105 | asm volatile( |
| 106 | " cs %0,%2,%1" |
| 107 | : "+d" (old), "=Q" (v->counter) |
| 108 | : "d" (new), "Q" (v->counter) |
| 109 | : "cc", "memory"); |
| 110 | #else /* __GNUC__ */ |
| 111 | asm volatile( |
| 112 | " cs %0,%3,0(%2)" |
| 113 | : "+d" (old), "=m" (v->counter) |
| 114 | : "a" (v), "d" (new), "m" (v->counter) |
| 115 | : "cc", "memory"); |
| 116 | #endif /* __GNUC__ */ |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 117 | return old; |
| 118 | } |
| 119 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 120 | static inline int atomic_add_unless(atomic_t *v, int a, int u) |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 121 | { |
| 122 | int c, old; |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 123 | c = atomic_read(v); |
Nick Piggin | 0b2fcfd | 2006-03-23 03:01:02 -0800 | [diff] [blame] | 124 | for (;;) { |
| 125 | if (unlikely(c == u)) |
| 126 | break; |
| 127 | old = atomic_cmpxchg(v, c, c + a); |
| 128 | if (likely(old == c)) |
| 129 | break; |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 130 | c = old; |
Nick Piggin | 0b2fcfd | 2006-03-23 03:01:02 -0800 | [diff] [blame] | 131 | } |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 132 | return c != u; |
| 133 | } |
| 134 | |
| 135 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | #undef __CS_LOOP |
| 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | #define ATOMIC64_INIT(i) { (i) } |
| 140 | |
Heiko Carstens | 1275105 | 2009-09-11 10:28:34 +0200 | [diff] [blame] | 141 | #ifdef CONFIG_64BIT |
| 142 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 143 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2) |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | #define __CSG_LOOP(ptr, op_val, op_string) ({ \ |
Martin Schwidefsky | 3947517 | 2009-12-07 12:52:05 +0100 | [diff] [blame^] | 146 | long long old_val, new_val; \ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 147 | asm volatile( \ |
| 148 | " lg %0,%2\n" \ |
| 149 | "0: lgr %1,%0\n" \ |
| 150 | op_string " %1,%3\n" \ |
| 151 | " csg %0,%1,%2\n" \ |
| 152 | " jl 0b" \ |
| 153 | : "=&d" (old_val), "=&d" (new_val), \ |
| 154 | "=Q" (((atomic_t *)(ptr))->counter) \ |
| 155 | : "d" (op_val), "Q" (((atomic_t *)(ptr))->counter) \ |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 156 | : "cc", "memory"); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | new_val; \ |
| 158 | }) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 159 | |
| 160 | #else /* __GNUC__ */ |
| 161 | |
| 162 | #define __CSG_LOOP(ptr, op_val, op_string) ({ \ |
Martin Schwidefsky | 3947517 | 2009-12-07 12:52:05 +0100 | [diff] [blame^] | 163 | long long old_val, new_val; \ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 164 | asm volatile( \ |
| 165 | " lg %0,0(%3)\n" \ |
| 166 | "0: lgr %1,%0\n" \ |
| 167 | op_string " %1,%4\n" \ |
| 168 | " csg %0,%1,0(%3)\n" \ |
| 169 | " jl 0b" \ |
| 170 | : "=&d" (old_val), "=&d" (new_val), \ |
| 171 | "=m" (((atomic_t *)(ptr))->counter) \ |
| 172 | : "a" (ptr), "d" (op_val), \ |
| 173 | "m" (((atomic_t *)(ptr))->counter) \ |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 174 | : "cc", "memory"); \ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 175 | new_val; \ |
| 176 | }) |
| 177 | |
| 178 | #endif /* __GNUC__ */ |
| 179 | |
Heiko Carstens | c51b962 | 2007-08-22 13:51:45 +0200 | [diff] [blame] | 180 | static inline long long atomic64_read(const atomic64_t *v) |
| 181 | { |
| 182 | barrier(); |
| 183 | return v->counter; |
| 184 | } |
| 185 | |
| 186 | static inline void atomic64_set(atomic64_t *v, long long i) |
| 187 | { |
| 188 | v->counter = i; |
| 189 | barrier(); |
| 190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 192 | static inline long long atomic64_add_return(long long i, atomic64_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | return __CSG_LOOP(v, i, "agr"); |
| 195 | } |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 196 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 197 | static inline long long atomic64_sub_return(long long i, atomic64_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 199 | return __CSG_LOOP(v, i, "sgr"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 201 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 202 | static inline void atomic64_clear_mask(unsigned long mask, atomic64_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 204 | __CSG_LOOP(v, ~mask, "ngr"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 206 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 207 | static inline void atomic64_set_mask(unsigned long mask, atomic64_t *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 209 | __CSG_LOOP(v, mask, "ogr"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Mathieu Desnoyers | 3a5f10e | 2007-02-21 10:55:59 +0100 | [diff] [blame] | 212 | #define atomic64_xchg(v, new) (xchg(&((v)->counter), new)) |
| 213 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 214 | static inline long long atomic64_cmpxchg(atomic64_t *v, |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 215 | long long old, long long new) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 217 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2) |
| 218 | asm volatile( |
| 219 | " csg %0,%2,%1" |
| 220 | : "+d" (old), "=Q" (v->counter) |
| 221 | : "d" (new), "Q" (v->counter) |
| 222 | : "cc", "memory"); |
| 223 | #else /* __GNUC__ */ |
| 224 | asm volatile( |
| 225 | " csg %0,%3,0(%2)" |
| 226 | : "+d" (old), "=m" (v->counter) |
| 227 | : "a" (v), "d" (new), "m" (v->counter) |
| 228 | : "cc", "memory"); |
| 229 | #endif /* __GNUC__ */ |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 230 | return old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Heiko Carstens | 1275105 | 2009-09-11 10:28:34 +0200 | [diff] [blame] | 233 | #undef __CSG_LOOP |
| 234 | |
| 235 | #else /* CONFIG_64BIT */ |
| 236 | |
| 237 | typedef struct { |
| 238 | long long counter; |
| 239 | } atomic64_t; |
| 240 | |
| 241 | static inline long long atomic64_read(const atomic64_t *v) |
| 242 | { |
| 243 | register_pair rp; |
| 244 | |
| 245 | asm volatile( |
| 246 | " lm %0,%N0,0(%1)" |
| 247 | : "=&d" (rp) |
| 248 | : "a" (&v->counter), "m" (v->counter) |
| 249 | ); |
| 250 | return rp.pair; |
| 251 | } |
| 252 | |
| 253 | static inline void atomic64_set(atomic64_t *v, long long i) |
| 254 | { |
| 255 | register_pair rp = {.pair = i}; |
| 256 | |
| 257 | asm volatile( |
| 258 | " stm %1,%N1,0(%2)" |
| 259 | : "=m" (v->counter) |
| 260 | : "d" (rp), "a" (&v->counter) |
| 261 | ); |
| 262 | } |
| 263 | |
| 264 | static inline long long atomic64_xchg(atomic64_t *v, long long new) |
| 265 | { |
| 266 | register_pair rp_new = {.pair = new}; |
| 267 | register_pair rp_old; |
| 268 | |
| 269 | asm volatile( |
| 270 | " lm %0,%N0,0(%2)\n" |
| 271 | "0: cds %0,%3,0(%2)\n" |
| 272 | " jl 0b\n" |
| 273 | : "=&d" (rp_old), "+m" (v->counter) |
| 274 | : "a" (&v->counter), "d" (rp_new) |
| 275 | : "cc"); |
| 276 | return rp_old.pair; |
| 277 | } |
| 278 | |
| 279 | static inline long long atomic64_cmpxchg(atomic64_t *v, |
| 280 | long long old, long long new) |
| 281 | { |
| 282 | register_pair rp_old = {.pair = old}; |
| 283 | register_pair rp_new = {.pair = new}; |
| 284 | |
| 285 | asm volatile( |
| 286 | " cds %0,%3,0(%2)" |
| 287 | : "+&d" (rp_old), "+m" (v->counter) |
| 288 | : "a" (&v->counter), "d" (rp_new) |
| 289 | : "cc"); |
| 290 | return rp_old.pair; |
| 291 | } |
| 292 | |
| 293 | |
| 294 | static inline long long atomic64_add_return(long long i, atomic64_t *v) |
| 295 | { |
| 296 | long long old, new; |
| 297 | |
| 298 | do { |
| 299 | old = atomic64_read(v); |
| 300 | new = old + i; |
| 301 | } while (atomic64_cmpxchg(v, old, new) != old); |
| 302 | return new; |
| 303 | } |
| 304 | |
| 305 | static inline long long atomic64_sub_return(long long i, atomic64_t *v) |
| 306 | { |
| 307 | long long old, new; |
| 308 | |
| 309 | do { |
| 310 | old = atomic64_read(v); |
| 311 | new = old - i; |
| 312 | } while (atomic64_cmpxchg(v, old, new) != old); |
| 313 | return new; |
| 314 | } |
| 315 | |
| 316 | static inline void atomic64_set_mask(unsigned long long mask, atomic64_t *v) |
| 317 | { |
| 318 | long long old, new; |
| 319 | |
| 320 | do { |
| 321 | old = atomic64_read(v); |
| 322 | new = old | mask; |
| 323 | } while (atomic64_cmpxchg(v, old, new) != old); |
| 324 | } |
| 325 | |
| 326 | static inline void atomic64_clear_mask(unsigned long long mask, atomic64_t *v) |
| 327 | { |
| 328 | long long old, new; |
| 329 | |
| 330 | do { |
| 331 | old = atomic64_read(v); |
| 332 | new = old & mask; |
| 333 | } while (atomic64_cmpxchg(v, old, new) != old); |
| 334 | } |
| 335 | |
| 336 | #endif /* CONFIG_64BIT */ |
| 337 | |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 338 | static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u) |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 339 | { |
| 340 | long long c, old; |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 341 | c = atomic64_read(v); |
Nick Piggin | 0b2fcfd | 2006-03-23 03:01:02 -0800 | [diff] [blame] | 342 | for (;;) { |
| 343 | if (unlikely(c == u)) |
| 344 | break; |
| 345 | old = atomic64_cmpxchg(v, c, c + a); |
| 346 | if (likely(old == c)) |
| 347 | break; |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 348 | c = old; |
Nick Piggin | 0b2fcfd | 2006-03-23 03:01:02 -0800 | [diff] [blame] | 349 | } |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 350 | return c != u; |
| 351 | } |
| 352 | |
Heiko Carstens | 1275105 | 2009-09-11 10:28:34 +0200 | [diff] [blame] | 353 | #define atomic64_add(_i, _v) atomic64_add_return(_i, _v) |
| 354 | #define atomic64_add_negative(_i, _v) (atomic64_add_return(_i, _v) < 0) |
| 355 | #define atomic64_inc(_v) atomic64_add_return(1, _v) |
| 356 | #define atomic64_inc_return(_v) atomic64_add_return(1, _v) |
| 357 | #define atomic64_inc_and_test(_v) (atomic64_add_return(1, _v) == 0) |
| 358 | #define atomic64_sub(_i, _v) atomic64_sub_return(_i, _v) |
| 359 | #define atomic64_sub_and_test(_i, _v) (atomic64_sub_return(_i, _v) == 0) |
| 360 | #define atomic64_dec(_v) atomic64_sub_return(1, _v) |
| 361 | #define atomic64_dec_return(_v) atomic64_sub_return(1, _v) |
| 362 | #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0) |
| 363 | #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) |
Nick Piggin | 8426e1f | 2005-11-13 16:07:25 -0800 | [diff] [blame] | 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | #define smp_mb__before_atomic_dec() smp_mb() |
| 366 | #define smp_mb__after_atomic_dec() smp_mb() |
| 367 | #define smp_mb__before_atomic_inc() smp_mb() |
| 368 | #define smp_mb__after_atomic_inc() smp_mb() |
| 369 | |
Arnd Bergmann | 72099ed | 2009-05-13 22:56:29 +0000 | [diff] [blame] | 370 | #include <asm-generic/atomic-long.h> |
Heiko Carstens | bfe3349b | 2009-09-11 10:28:35 +0200 | [diff] [blame] | 371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | #endif /* __ARCH_S390_ATOMIC__ */ |