X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=include%2Furcu%2Fuatomic.h;fp=include%2Furcu%2Fuatomic.h;h=5365f1fb0fdac0159edb06835f639b3045cc79eb;hp=b7b1d89d0ca1c6e66209ccfcfc4f2b76f9ebaf36;hb=d18544842bdfbf2cba6c194a8e8d305ddf5e295e;hpb=72d24c88ee075c8368fe57ee7e8fc66d99ce7e39 diff --git a/include/urcu/uatomic.h b/include/urcu/uatomic.h index b7b1d89..5365f1f 100644 --- a/include/urcu/uatomic.h +++ b/include/urcu/uatomic.h @@ -5,9 +5,70 @@ #ifndef _URCU_UATOMIC_H #define _URCU_UATOMIC_H +#include + #include +#include + +enum cmm_memorder { + CMM_RELAXED = 0, + CMM_CONSUME = 1, + CMM_ACQUIRE = 2, + CMM_RELEASE = 3, + CMM_ACQ_REL = 4, + CMM_SEQ_CST = 5, + CMM_SEQ_CST_FENCE = 6, +}; + +#ifdef CONFIG_RCU_USE_ATOMIC_BUILTINS + +/* + * Make sure that CMM_SEQ_CST_FENCE is not equivalent to other memory orders. + */ +# ifdef static_assert +static_assert(CMM_RELAXED == __ATOMIC_RELAXED, ""); +static_assert(CMM_CONSUME == __ATOMIC_CONSUME, ""); +static_assert(CMM_ACQUIRE == __ATOMIC_ACQUIRE, ""); +static_assert(CMM_RELEASE == __ATOMIC_RELEASE, ""); +static_assert(CMM_ACQ_REL == __ATOMIC_ACQ_REL, ""); +static_assert(CMM_SEQ_CST == __ATOMIC_SEQ_CST, ""); +# endif + +/* + * This is not part of the public API. It it used internally to implement the + * CMM_SEQ_CST_FENCE memory order. + * + * NOTE: Using switch here instead of if statement to avoid -Wduplicated-cond + * warning when memory order is conditionally determined. + */ +static inline void cmm_seq_cst_fence_after_atomic(enum cmm_memorder mo) +{ + switch (mo) { + case CMM_SEQ_CST_FENCE: + cmm_smp_mb(); + break; + default: + break; + } +} + +#endif + +/* + * This is not part of the public API. It is used internally to convert from the + * CMM memory model to the C11 memory model. + */ +static inline int cmm_to_c11(int mo) +{ + if (mo == CMM_SEQ_CST_FENCE) { + return CMM_SEQ_CST; + } + return mo; +} -#if defined(URCU_ARCH_X86) +#if defined(CONFIG_RCU_USE_ATOMIC_BUILTINS) +#include +#elif defined(URCU_ARCH_X86) #include #elif defined(URCU_ARCH_PPC) #include