|
3 | 3 |
|
4 | 4 | #include <linux/types.h> |
5 | 5 | #include <asm/barrier.h> |
6 | | -#include <asm/system.h> |
7 | 6 |
|
8 | 7 | /* |
9 | 8 | * Atomic operations that C can't guarantee us. Useful for |
@@ -169,6 +168,73 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v) |
169 | 168 | return result; |
170 | 169 | } |
171 | 170 |
|
| 171 | +/* |
| 172 | + * Atomic exchange routines. |
| 173 | + */ |
| 174 | + |
| 175 | +#define __ASM__MB |
| 176 | +#define ____xchg(type, args...) __xchg ## type ## _local(args) |
| 177 | +#define ____cmpxchg(type, args...) __cmpxchg ## type ## _local(args) |
| 178 | +#include <asm/xchg.h> |
| 179 | + |
| 180 | +#define xchg_local(ptr,x) \ |
| 181 | + ({ \ |
| 182 | + __typeof__(*(ptr)) _x_ = (x); \ |
| 183 | + (__typeof__(*(ptr))) __xchg_local((ptr), (unsigned long)_x_, \ |
| 184 | + sizeof(*(ptr))); \ |
| 185 | + }) |
| 186 | + |
| 187 | +#define cmpxchg_local(ptr, o, n) \ |
| 188 | + ({ \ |
| 189 | + __typeof__(*(ptr)) _o_ = (o); \ |
| 190 | + __typeof__(*(ptr)) _n_ = (n); \ |
| 191 | + (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \ |
| 192 | + (unsigned long)_n_, \ |
| 193 | + sizeof(*(ptr))); \ |
| 194 | + }) |
| 195 | + |
| 196 | +#define cmpxchg64_local(ptr, o, n) \ |
| 197 | + ({ \ |
| 198 | + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ |
| 199 | + cmpxchg_local((ptr), (o), (n)); \ |
| 200 | + }) |
| 201 | + |
| 202 | +#ifdef CONFIG_SMP |
| 203 | +#undef __ASM__MB |
| 204 | +#define __ASM__MB "\tmb\n" |
| 205 | +#endif |
| 206 | +#undef ____xchg |
| 207 | +#undef ____cmpxchg |
| 208 | +#define ____xchg(type, args...) __xchg ##type(args) |
| 209 | +#define ____cmpxchg(type, args...) __cmpxchg ##type(args) |
| 210 | +#include <asm/xchg.h> |
| 211 | + |
| 212 | +#define xchg(ptr,x) \ |
| 213 | + ({ \ |
| 214 | + __typeof__(*(ptr)) _x_ = (x); \ |
| 215 | + (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, \ |
| 216 | + sizeof(*(ptr))); \ |
| 217 | + }) |
| 218 | + |
| 219 | +#define cmpxchg(ptr, o, n) \ |
| 220 | + ({ \ |
| 221 | + __typeof__(*(ptr)) _o_ = (o); \ |
| 222 | + __typeof__(*(ptr)) _n_ = (n); \ |
| 223 | + (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \ |
| 224 | + (unsigned long)_n_, sizeof(*(ptr)));\ |
| 225 | + }) |
| 226 | + |
| 227 | +#define cmpxchg64(ptr, o, n) \ |
| 228 | + ({ \ |
| 229 | + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ |
| 230 | + cmpxchg((ptr), (o), (n)); \ |
| 231 | + }) |
| 232 | + |
| 233 | +#undef __ASM__MB |
| 234 | +#undef ____cmpxchg |
| 235 | + |
| 236 | +#define __HAVE_ARCH_CMPXCHG 1 |
| 237 | + |
172 | 238 | #define atomic64_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), old, new)) |
173 | 239 | #define atomic64_xchg(v, new) (xchg(&((v)->counter), new)) |
174 | 240 |
|
|
0 commit comments