This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a45843f7ce267d78d85dd90d2ad83d7641d492c3 Author: Bowen Wang <[email protected]> AuthorDate: Tue Sep 1 18:03:51 2026 +0800 libc/atomic: merge tricore arch_atomic.c into machine/arch_atomic.c 1. Add ARCH_HAVE_ATOMIC_4 guard in arch/tricore/include/atomic.h so the tricore arch declares which sizes have hardware atomic support. 2. Extend include/nuttx/lib/arch_atomic.h to #undef arch overrides and provide IRQ-based inline fallback for sizes the arch does not support, so generic code covers all {1,2,4,8} sizes uniformly. 3. Update libs/libc/machine/arch_atomic.c to gate per-size symbol export on ARCH_HAVE_ATOMIC_X and 64-bit on UINTPTR_MAX > UINT32_MAX; delete libs/libc/machine/tricore/arch_atomic.c (now merged into the generic machine/arch_atomic.c). 4. Drop tricore-specific arch_atomic.c references from libs/libc/machine/tricore/{Make.defs,CMakeLists.txt}. Signed-off-by: Bowen Wang <[email protected]> --- arch/tricore/include/atomic.h | 2 ++ include/nuttx/lib/arch_atomic.h | 5 +++++ libs/libc/machine/CMakeLists.txt | 2 +- libs/libc/machine/Make.defs | 2 +- libs/libc/machine/arch_atomic.c | 16 ++++++++++++++ libs/libc/machine/tricore/CMakeLists.txt | 4 ---- libs/libc/machine/tricore/Make.defs | 4 ---- libs/libc/machine/tricore/arch_atomic.c | 37 -------------------------------- 8 files changed, 25 insertions(+), 47 deletions(-) diff --git a/arch/tricore/include/atomic.h b/arch/tricore/include/atomic.h index 67aed769618..b1232f7b8ec 100644 --- a/arch/tricore/include/atomic.h +++ b/arch/tricore/include/atomic.h @@ -112,6 +112,8 @@ ARCH_ATOMIC_FETCH_OP(prefix ## _fetch_or_ ## n, t, n, |) \ ARCH_ATOMIC_FETCH_OP(prefix ## _fetch_xor_ ## n, t, n, ^) +#define ARCH_HAVE_ATOMIC_4 + /**************************************************************************** * Inline Functions ****************************************************************************/ diff --git a/include/nuttx/lib/arch_atomic.h b/include/nuttx/lib/arch_atomic.h index a578999d3f2..c579ee40029 100644 --- a/include/nuttx/lib/arch_atomic.h +++ b/include/nuttx/lib/arch_atomic.h @@ -271,6 +271,11 @@ static inline void atomic_unlock(irqstate_t flags) ARCH_SYNC_BOOL_CMP_SWAP(prefix ## _bool_compare_and_swap_ ## n, t) \ ARCH_SYNC_VAL_CMP_SWAP(prefix ## _val_compare_and_swap_ ## n, t) +#define ARCH_HAVE_ATOMIC_1 +#define ARCH_HAVE_ATOMIC_2 +#define ARCH_HAVE_ATOMIC_4 +#define ARCH_HAVE_ATOMIC_8 + /**************************************************************************** * Inline Functions ****************************************************************************/ diff --git a/libs/libc/machine/CMakeLists.txt b/libs/libc/machine/CMakeLists.txt index e2dfd540857..1c9542380a0 100644 --- a/libs/libc/machine/CMakeLists.txt +++ b/libs/libc/machine/CMakeLists.txt @@ -22,7 +22,7 @@ add_subdirectory(${CONFIG_ARCH}) -if(CONFIG_LIBC_ATOMIC_IRQ OR CONFIG_LIBC_ATOMIC_HWSPINLOCK) +if(NOT CONFIG_LIBC_ATOMIC_TOOLCHAIN) target_sources(c PRIVATE arch_atomic.c) endif() diff --git a/libs/libc/machine/Make.defs b/libs/libc/machine/Make.defs index ef340bd54ca..af1a0636b56 100644 --- a/libs/libc/machine/Make.defs +++ b/libs/libc/machine/Make.defs @@ -20,7 +20,7 @@ # ############################################################################ -ifneq ($(filter y,$(CONFIG_LIBC_ATOMIC_IRQ)$(CONFIG_LIBC_ATOMIC_HWSPINLOCK)),) +ifneq ($(CONFIG_LIBC_ATOMIC_TOOLCHAIN),y) CSRCS += arch_atomic.c endif diff --git a/libs/libc/machine/arch_atomic.c b/libs/libc/machine/arch_atomic.c index db63a72899b..9eed7d6a6df 100644 --- a/libs/libc/machine/arch_atomic.c +++ b/libs/libc/machine/arch_atomic.c @@ -38,10 +38,18 @@ * Name: __atomic_*_{1,2,4,8} ****************************************************************************/ +#ifdef ARCH_HAVE_ATOMIC_1 ARCH_ATOMIC_DEFINE(__atomic, uint8_t, 1) +#endif +#ifdef ARCH_HAVE_ATOMIC_2 ARCH_ATOMIC_DEFINE(__atomic, uint16_t, 2) +#endif +#ifdef ARCH_HAVE_ATOMIC_4 ARCH_ATOMIC_DEFINE(__atomic, uint32_t, 4) +#endif +#ifdef ARCH_HAVE_ATOMIC_8 ARCH_ATOMIC_DEFINE(__atomic, uint64_t, 8) +#endif /* Clang define the __sync builtins, add #ifndef to avoid * redefined/redeclared problem. @@ -54,10 +62,18 @@ ARCH_ATOMIC_DEFINE(__atomic, uint64_t, 8) ****************************************************************************/ #ifdef ARCH_SYNC_DEFINE +# ifdef ARCH_HAVE_ATOMIC_1 ARCH_SYNC_DEFINE(__sync, uint8_t, 1) +# endif +# ifdef ARCH_HAVE_ATOMIC_2 ARCH_SYNC_DEFINE(__sync, uint16_t, 2) +# endif +# ifdef ARCH_HAVE_ATOMIC_4 ARCH_SYNC_DEFINE(__sync, uint32_t, 4) +# endif +# ifdef ARCH_HAVE_ATOMIC_8 ARCH_SYNC_DEFINE(__sync, uint64_t, 8) +# endif #endif /**************************************************************************** diff --git a/libs/libc/machine/tricore/CMakeLists.txt b/libs/libc/machine/tricore/CMakeLists.txt index 4f5d244739d..af9b3f05eee 100644 --- a/libs/libc/machine/tricore/CMakeLists.txt +++ b/libs/libc/machine/tricore/CMakeLists.txt @@ -22,10 +22,6 @@ set(SRCS) -if(CONFIG_LIBC_ATOMIC_ARCH) - list(APPEND SRCS arch_atomic.c) -endif() - if(CONFIG_TRICORE_TOOLCHAIN_TASKING) set(TRICORE_SUBDIR tasking) else() diff --git a/libs/libc/machine/tricore/Make.defs b/libs/libc/machine/tricore/Make.defs index 55e92cfe4aa..16ff94b4b06 100644 --- a/libs/libc/machine/tricore/Make.defs +++ b/libs/libc/machine/tricore/Make.defs @@ -20,10 +20,6 @@ # ############################################################################ -ifeq ($(CONFIG_LIBC_ATOMIC_ARCH),y) -CSRCS += arch_atomic.c -endif - ifeq ($(CONFIG_TRICORE_TOOLCHAIN_TASKING),y) TRICORE_SUBDIR = tasking else diff --git a/libs/libc/machine/tricore/arch_atomic.c b/libs/libc/machine/tricore/arch_atomic.c deleted file mode 100644 index a834d5ad975..00000000000 --- a/libs/libc/machine/tricore/arch_atomic.c +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** - * libs/libc/machine/tricore/arch_atomic.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#define ARCH_ATOMIC_SPECIFIER - -#include <nuttx/atomic.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -ARCH_ATOMIC_DEFINE(__atomic, int32_t, 4)
