X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=include%2Furcu%2Fuatomic.h;h=aca9a63da3af2d5301b92daa47fa5cdbfcedfa4b;hb=455a8429f01ee5f98161bd8710c50ba0bdec61f2;hp=2fb5fd40eefcc127547bdd84f04dd1d161c7e6b0;hpb=0b1e236d1711f4f9076f73a093ece05aca00eca4;p=urcu.git diff --git a/include/urcu/uatomic.h b/include/urcu/uatomic.h index 2fb5fd4..aca9a63 100644 --- a/include/urcu/uatomic.h +++ b/include/urcu/uatomic.h @@ -1,29 +1,71 @@ -/* - * urcu/uatomic.h - * - * Copyright (c) 2020 Michael Jeanson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-FileCopyrightText: 2020 Michael Jeanson +// +// SPDX-License-Identifier: LGPL-2.1-or-later #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. + */ +urcu_static_assert(CMM_RELAXED == __ATOMIC_RELAXED, "", cmm_relaxed); +urcu_static_assert(CMM_CONSUME == __ATOMIC_CONSUME, "", cmm_consume); +urcu_static_assert(CMM_ACQUIRE == __ATOMIC_ACQUIRE, "", cmm_acquire); +urcu_static_assert(CMM_RELEASE == __ATOMIC_RELEASE, "", cmm_release); +urcu_static_assert(CMM_ACQ_REL == __ATOMIC_ACQ_REL, "", cmm_acq_rel); +urcu_static_assert(CMM_SEQ_CST == __ATOMIC_SEQ_CST, "", cmm_seq_cst); + +/* + * 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