1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ALPHA_CMPXCHG_H
3 #define _ALPHA_CMPXCHG_H
6 * Atomic exchange routines.
10 #define ____xchg(type, args...) __xchg ## type ## _local(args)
11 #define ____cmpxchg(type, args...) __cmpxchg ## type ## _local(args)
14 #define xchg_local(ptr, x) \
16 __typeof__(*(ptr)) _x_ = (x); \
17 (__typeof__(*(ptr))) __xchg_local((ptr), (unsigned long)_x_, \
21 #define cmpxchg_local(ptr, o, n) \
23 __typeof__(*(ptr)) _o_ = (o); \
24 __typeof__(*(ptr)) _n_ = (n); \
25 (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \
30 #define cmpxchg64_local(ptr, o, n) \
32 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
33 cmpxchg_local((ptr), (o), (n)); \
38 #define __ASM__MB "\tmb\n"
42 #define ____xchg(type, args...) __xchg ##type(args)
43 #define ____cmpxchg(type, args...) __cmpxchg ##type(args)
46 #define xchg(ptr, x) \
48 __typeof__(*(ptr)) _x_ = (x); \
49 (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, \
53 #define cmpxchg(ptr, o, n) \
55 __typeof__(*(ptr)) _o_ = (o); \
56 __typeof__(*(ptr)) _n_ = (n); \
57 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
58 (unsigned long)_n_, sizeof(*(ptr)));\
61 #define cmpxchg64(ptr, o, n) \
63 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
64 cmpxchg((ptr), (o), (n)); \
70 #endif /* _ALPHA_CMPXCHG_H */