From 13315c1bdbdfb2edcd7b0e8de0d1d1158e8452dc Mon Sep 17 00:00:00 2001 From: hujun5 Date: Fri, 29 Nov 2024 16:12:05 +0800 Subject: [PATCH] bt_atomic: use atomic macro to replace wireless/bluetooth/bt_atomic.c Signed-off-by: hujun5 --- wireless/bluetooth/CMakeLists.txt | 1 - wireless/bluetooth/Make.defs | 2 +- wireless/bluetooth/bt_atomic.c | 112 ------------------------------ wireless/bluetooth/bt_atomic.h | 26 +++---- 4 files changed, 11 insertions(+), 130 deletions(-) delete mode 100644 wireless/bluetooth/bt_atomic.c diff --git a/wireless/bluetooth/CMakeLists.txt b/wireless/bluetooth/CMakeLists.txt index 141dd73d1f215..1519d211a51da 100644 --- a/wireless/bluetooth/CMakeLists.txt +++ b/wireless/bluetooth/CMakeLists.txt @@ -29,7 +29,6 @@ if(CONFIG_WIRELESS_BLUETOOTH) list( APPEND SRCS - bt_atomic.c bt_att.c bt_conn.c bt_gatt.c diff --git a/wireless/bluetooth/Make.defs b/wireless/bluetooth/Make.defs index b3511bc34168b..42a5c0e70aa22 100644 --- a/wireless/bluetooth/Make.defs +++ b/wireless/bluetooth/Make.defs @@ -30,7 +30,7 @@ ifeq ($(CONFIG_WIRELESS_BLUETOOTH_HOST),y) # Host-layer -CSRCS += bt_atomic.c bt_att.c bt_conn.c bt_gatt.c +CSRCS += bt_att.c bt_conn.c bt_gatt.c CSRCS += bt_ioctl.c bt_keys.c bt_l2cap.c bt_smp.c CSRCS += bt_uuid.c bt_services.c diff --git a/wireless/bluetooth/bt_atomic.c b/wireless/bluetooth/bt_atomic.c deleted file mode 100644 index 1a3f088fe9812..0000000000000 --- a/wireless/bluetooth/bt_atomic.c +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** - * wireless/bluetooth/bt_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 -#include - -#include "bt_atomic.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -bt_atomic_t bt_atomic_incr(FAR bt_atomic_t *ptr) -{ - irqstate_t flags; - bt_atomic_t value; - - flags = spin_lock_irqsave(NULL); - value = *ptr; - *ptr = value + 1; - spin_unlock_irqrestore(NULL, flags); - - return value; -} - -bt_atomic_t bt_atomic_decr(FAR bt_atomic_t *ptr) -{ - irqstate_t flags; - bt_atomic_t value; - - flags = spin_lock_irqsave(NULL); - value = *ptr; - *ptr = value - 1; - spin_unlock_irqrestore(NULL, flags); - - return value; -} - -bt_atomic_t bt_atomic_setbit(FAR bt_atomic_t *ptr, bt_atomic_t bitno) -{ - irqstate_t flags; - bt_atomic_t value; - - flags = spin_lock_irqsave(NULL); - value = *ptr; - *ptr = value | (1 << bitno); - spin_unlock_irqrestore(NULL, flags); - - return value; -} - -bt_atomic_t bt_atomic_clrbit(FAR bt_atomic_t *ptr, bt_atomic_t bitno) -{ - irqstate_t flags; - bt_atomic_t value; - - flags = spin_lock_irqsave(NULL); - value = *ptr; - *ptr = value & ~(1 << bitno); - spin_unlock_irqrestore(NULL, flags); - - return value; -} - -bool bt_atomic_testsetbit(FAR bt_atomic_t *ptr, bt_atomic_t bitno) -{ - irqstate_t flags; - bt_atomic_t value; - - flags = spin_lock_irqsave(NULL); - value = *ptr; - *ptr = value | (1 << bitno); - spin_unlock_irqrestore(NULL, flags); - - return (value & (1 << bitno)) != 0; -} - -bool bt_atomic_testclrbit(FAR bt_atomic_t *ptr, bt_atomic_t bitno) -{ - irqstate_t flags; - bt_atomic_t value; - - flags = spin_lock_irqsave(NULL); - value = *ptr; - *ptr = value & ~(1 << bitno); - spin_unlock_irqrestore(NULL, flags); - - return (value & (1 << bitno)) != 0; -} diff --git a/wireless/bluetooth/bt_atomic.h b/wireless/bluetooth/bt_atomic.h index 56af173350416..ea87754d546e5 100644 --- a/wireless/bluetooth/bt_atomic.h +++ b/wireless/bluetooth/bt_atomic.h @@ -37,26 +37,20 @@ * Pre-processor Definitions ****************************************************************************/ -#define bt_atomic_set(ptr, value) (*(ptr) = (value)) -#define bt_atomic_get(ptr) (*(ptr)) -#define bt_atomic_testbit(ptr, bitno) ((*(ptr) & (1 << (bitno))) != 0) +#define bt_atomic_set(ptr, value) atomic_store(ptr, value); +#define bt_atomic_get(ptr) atomic_load(ptr) +#define bt_atomic_testbit(ptr, bitno) ((atomic_load(ptr) & (1 << (bitno))) != 0) +#define bt_atomic_incr(ptr) atomic_fetch_add(ptr, 1) +#define bt_atomic_decr(ptr) atomic_fetch_sub(ptr, 1) +#define bt_atomic_setbit(ptr, bitno) atomic_fetch_or(ptr, (1 << (bitno))) +#define bt_atomic_clrbit(ptr, bitno) atomic_fetch_and(ptr, ~(1 << (bitno))) +#define bt_atomic_testsetbit(ptr, bitno) ((atomic_fetch_or(ptr, (1 << (bitno))) & (1 << (bitno))) != 0) +#define bt_atomic_testclrbit(ptr, bitno) ((atomic_fetch_and(ptr, ~(1 << (bitno))) & (1 << (bitno))) != 0) /**************************************************************************** * Public Types ****************************************************************************/ -typedef uint8_t bt_atomic_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -bt_atomic_t bt_atomic_incr(FAR bt_atomic_t *ptr); -bt_atomic_t bt_atomic_decr(FAR bt_atomic_t *ptr); -bt_atomic_t bt_atomic_setbit(FAR bt_atomic_t *ptr, bt_atomic_t bitno); -bt_atomic_t bt_atomic_clrbit(FAR bt_atomic_t *ptr, bt_atomic_t bitno); - -bool bt_atomic_testsetbit(FAR bt_atomic_t *ptr, bt_atomic_t bitno); -bool bt_atomic_testclrbit(FAR bt_atomic_t *ptr, bt_atomic_t bitno); +typedef atomic_char bt_atomic_t; #endif /* __WIRELESS_BLUETOOTH_BT_ATOMIC_H */