From 667e92390b7efcfc76419a483597ac063590bf60 Mon Sep 17 00:00:00 2001 From: chenrun1 Date: Fri, 26 Jul 2024 19:35:53 +0800 Subject: [PATCH] nuttx/atomic.h:replace ALL stdatomic.h with nuttx/stdatomic.h in nuttx/ Summary: 1. Add nuttx/atomic.h in include 2. Use nuttx/atomic.h instead of stdatomic.h in the nuttx directory Signed-off-by: chenrun1 --- arch/sim/src/sim/sim_heap.c | 2 +- drivers/note/notesnap_driver.c | 3 +- drivers/wireless/bluetooth/bt_bridge.c | 2 +- include/nuttx/atomic.h | 64 ++++++++++++++++++++++++++ include/nuttx/reset/reset.h | 2 +- include/nuttx/serial/uart_ram.h | 2 +- include/nuttx/spinlock.h | 29 ++---------- 7 files changed, 73 insertions(+), 31 deletions(-) create mode 100644 include/nuttx/atomic.h diff --git a/arch/sim/src/sim/sim_heap.c b/arch/sim/src/sim/sim_heap.c index 5095bb5654..f974660421 100644 --- a/arch/sim/src/sim/sim_heap.c +++ b/arch/sim/src/sim/sim_heap.c @@ -27,10 +27,10 @@ #include #include #include -#include #include #include +#include #include #include diff --git a/drivers/note/notesnap_driver.c b/drivers/note/notesnap_driver.c index 8925584b4c..097aaed80c 100644 --- a/drivers/note/notesnap_driver.c +++ b/drivers/note/notesnap_driver.c @@ -22,8 +22,7 @@ * Included Files ****************************************************************************/ -#include - +#include #include #include #include diff --git a/drivers/wireless/bluetooth/bt_bridge.c b/drivers/wireless/bluetooth/bt_bridge.c index 461ae618f8..b82764c562 100644 --- a/drivers/wireless/bluetooth/bt_bridge.c +++ b/drivers/wireless/bluetooth/bt_bridge.c @@ -23,10 +23,10 @@ ****************************************************************************/ #include -#include #include #include +#include #include #include diff --git a/include/nuttx/atomic.h b/include/nuttx/atomic.h new file mode 100644 index 0000000000..1738e6441a --- /dev/null +++ b/include/nuttx/atomic.h @@ -0,0 +1,64 @@ +/**************************************************************************** + * include/nuttx/atomic.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_ATOMIC_H +#define __INCLUDE_NUTTX_ATOMIC_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#if !defined(__cplusplus) || defined(__clang__) +# include +#elif defined(__has_include) && __has_include() +extern "C++" +{ +# include + using std::atomic_int; + using std::atomic_uint; + using std::atomic_ushort; + using std::atomic_load; + using std::atomic_store; + using std::atomic_fetch_add; + using std::atomic_fetch_sub; + using std::atomic_compare_exchange_strong; +# define ATOMIC_VAR_INIT(value) (value) +} +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_NUTTX_ATOMIC_H */ diff --git a/include/nuttx/reset/reset.h b/include/nuttx/reset/reset.h index f01bc4b11d..8df7ca0faa 100644 --- a/include/nuttx/reset/reset.h +++ b/include/nuttx/reset/reset.h @@ -26,9 +26,9 @@ ****************************************************************************/ #include -#include #include +#include #include /**************************************************************************** diff --git a/include/nuttx/serial/uart_ram.h b/include/nuttx/serial/uart_ram.h index ad7e1e5125..726db4abf0 100644 --- a/include/nuttx/serial/uart_ram.h +++ b/include/nuttx/serial/uart_ram.h @@ -29,8 +29,8 @@ #ifdef CONFIG_RAM_UART -#include #include +#include /**************************************************************************** * Pre-processor Definitions diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index ebb5d91328..d226f3504a 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -31,31 +31,13 @@ #include #include -#if defined(CONFIG_TICKET_SPINLOCK) || defined(CONFIG_RW_SPINLOCK) -# if !defined(__cplusplus) -# include -# define CONFIG_HAVE_INLINE_SPINLOCK -# elif defined(__has_include) && __has_include() -extern "C++" -{ -# include -# define CONFIG_HAVE_INLINE_SPINLOCK - using std::atomic_int; - using std::atomic_load; - using std::atomic_uint; - using std::atomic_ushort; - using std::atomic_fetch_add; - using std::atomic_fetch_sub; - using std::atomic_compare_exchange_strong; -} -# endif -#else -# define CONFIG_HAVE_INLINE_SPINLOCK -#endif - #include #include +#if defined(CONFIG_TICKET_SPINLOCK) || defined(CONFIG_RW_SPINLOCK) +# include +#endif + #undef EXTERN #if defined(__cplusplus) #define EXTERN extern "C" @@ -232,8 +214,6 @@ static inline spinlock_t up_testset(FAR volatile spinlock_t *lock) /* void spin_lock_init(FAR spinlock_t *lock); */ #define spin_lock_init(l) do { *(l) = SP_UNLOCKED; } while (0) -#ifdef CONFIG_HAVE_INLINE_SPINLOCK - /**************************************************************************** * Name: spin_lock_wo_note * @@ -1172,7 +1152,6 @@ void write_unlock_irqrestore(FAR rwlock_t *lock, irqstate_t flags); #endif #endif /* CONFIG_RW_SPINLOCK */ -#endif /* CONFIG_HAVE_INLINE_SPINLOCK */ #undef EXTERN #if defined(__cplusplus)