bt_atomic: use atomic macro to replace wireless/bluetooth/bt_atomic.c

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2024-11-29 16:12:05 +08:00 committed by Xiang Xiao
parent 5358f5b940
commit 5ed007a0f3
4 changed files with 11 additions and 130 deletions

View file

@ -29,7 +29,6 @@ if(CONFIG_WIRELESS_BLUETOOTH)
list(
APPEND
SRCS
bt_atomic.c
bt_att.c
bt_conn.c
bt_gatt.c

View file

@ -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

View file

@ -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 <nuttx/config.h>
#include <nuttx/spinlock.h>
#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;
}

View file

@ -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 */