Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ALPHA_CMPXCHG_H
0003 #define _ALPHA_CMPXCHG_H
0004 
0005 /*
0006  * Atomic exchange routines.
0007  */
0008 
0009 #define ____xchg(type, args...)     __xchg ## type ## _local(args)
0010 #define ____cmpxchg(type, args...)  __cmpxchg ## type ## _local(args)
0011 #include <asm/xchg.h>
0012 
0013 #define xchg_local(ptr, x)                      \
0014 ({                                  \
0015     __typeof__(*(ptr)) _x_ = (x);                   \
0016     (__typeof__(*(ptr))) __xchg_local((ptr), (unsigned long)_x_,    \
0017                        sizeof(*(ptr)));         \
0018 })
0019 
0020 #define arch_cmpxchg_local(ptr, o, n)                   \
0021 ({                                  \
0022     __typeof__(*(ptr)) _o_ = (o);                   \
0023     __typeof__(*(ptr)) _n_ = (n);                   \
0024     (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \
0025                       (unsigned long)_n_,       \
0026                       sizeof(*(ptr)));      \
0027 })
0028 
0029 #define arch_cmpxchg64_local(ptr, o, n)                 \
0030 ({                                  \
0031     BUILD_BUG_ON(sizeof(*(ptr)) != 8);              \
0032     cmpxchg_local((ptr), (o), (n));                 \
0033 })
0034 
0035 #undef ____xchg
0036 #undef ____cmpxchg
0037 #define ____xchg(type, args...)     __xchg ##type(args)
0038 #define ____cmpxchg(type, args...)  __cmpxchg ##type(args)
0039 #include <asm/xchg.h>
0040 
0041 /*
0042  * The leading and the trailing memory barriers guarantee that these
0043  * operations are fully ordered.
0044  */
0045 #define arch_xchg(ptr, x)                       \
0046 ({                                  \
0047     __typeof__(*(ptr)) __ret;                   \
0048     __typeof__(*(ptr)) _x_ = (x);                   \
0049     smp_mb();                           \
0050     __ret = (__typeof__(*(ptr)))                    \
0051         __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr)));  \
0052     smp_mb();                           \
0053     __ret;                              \
0054 })
0055 
0056 #define arch_cmpxchg(ptr, o, n)                     \
0057 ({                                  \
0058     __typeof__(*(ptr)) __ret;                   \
0059     __typeof__(*(ptr)) _o_ = (o);                   \
0060     __typeof__(*(ptr)) _n_ = (n);                   \
0061     smp_mb();                           \
0062     __ret = (__typeof__(*(ptr))) __cmpxchg((ptr),           \
0063         (unsigned long)_o_, (unsigned long)_n_, sizeof(*(ptr)));\
0064     smp_mb();                           \
0065     __ret;                              \
0066 })
0067 
0068 #define arch_cmpxchg64(ptr, o, n)                   \
0069 ({                                  \
0070     BUILD_BUG_ON(sizeof(*(ptr)) != 8);              \
0071     arch_cmpxchg((ptr), (o), (n));                  \
0072 })
0073 
0074 #undef ____cmpxchg
0075 
0076 #endif /* _ALPHA_CMPXCHG_H */