nuttx/atomic.h:replace ALL stdatomic.h with nuttx/stdatomic.h in nuttx/

Summary:
 1. use nuttx/atomic.h instead of stdatomic
 2. remove CONFIG_HAVE_ATOMIC,because we now support atomic on all platforms

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
This commit is contained in:
chenrun1 2024-08-06 16:00:56 +08:00 committed by Xiang Xiao
parent 8e1a042eef
commit cfcf347515
4 changed files with 8 additions and 73 deletions

View file

@ -85,42 +85,6 @@ struct netdev_upperhalf_s
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: quota_fetch_inc/dec
*
* Description:
* Fetch the quota and add/sub one to it. It works like atomic_fetch_xxx,
* just because currently we don't have atomic on some platform. We may
* switch to atomic later.
*
****************************************************************************/
static int quota_fetch_inc(FAR struct netdev_lowerhalf_s *lower,
enum netpkt_type_e type)
{
#ifndef CONFIG_HAVE_ATOMICS
irqstate_t flags = spin_lock_irqsave(&lower->lock);
int ret = lower->quota[type]++;
spin_unlock_irqrestore(&lower->lock, flags);
return ret;
#else
return atomic_fetch_add(&lower->quota[type], 1);
#endif
}
static int quota_fetch_dec(FAR struct netdev_lowerhalf_s *lower,
enum netpkt_type_e type)
{
#ifndef CONFIG_HAVE_ATOMICS
irqstate_t flags = spin_lock_irqsave(&lower->lock);
int ret = lower->quota[type]--;
spin_unlock_irqrestore(&lower->lock, flags);
return ret;
#else
return atomic_fetch_sub(&lower->quota[type], 1);
#endif
}
/****************************************************************************
* Name: quota_is_valid
*
@ -183,7 +147,7 @@ static FAR netpkt_t *netpkt_get(FAR struct net_driver_s *dev,
* cases will be limited by netdev_upper_can_tx and seldom reaches here.
*/
if (quota_fetch_dec(upper->lower, type) <= 0)
if (atomic_fetch_sub(&upper->lower->quota[type], 1) <= 0)
{
nwarn("WARNING: Allowing temperarily exceeding quota of %s.\n",
dev->d_ifname);
@ -215,7 +179,7 @@ static void netpkt_put(FAR struct net_driver_s *dev, FAR netpkt_t *pkt,
* but we don't want these changes.
*/
quota_fetch_inc(upper->lower, type);
atomic_fetch_add(&upper->lower->quota[type], 1);
netdev_iob_release(dev);
dev->d_iob = pkt;
dev->d_len = netpkt_getdatalen(upper->lower, pkt);
@ -1204,9 +1168,6 @@ int netdev_lower_register(FAR struct netdev_lowerhalf_s *dev,
return -ENOMEM;
}
#ifndef CONFIG_HAVE_ATOMICS
spin_initialize(&dev->lock, SP_UNLOCKED);
#endif
dev->netdev.d_ifup = netdev_upper_ifup;
dev->netdev.d_ifdown = netdev_upper_ifdown;
dev->netdev.d_txavail = netdev_upper_txavail;
@ -1375,14 +1336,7 @@ void netdev_lower_txdone(FAR struct netdev_lowerhalf_s *dev)
int netdev_lower_quota_load(FAR struct netdev_lowerhalf_s *dev,
enum netpkt_type_e type)
{
#ifndef CONFIG_HAVE_ATOMICS
irqstate_t flags = spin_lock_irqsave(&dev->lock);
int ret = dev->quota[type];
spin_unlock_irqrestore(&dev->lock, flags);
return ret;
#else
return atomic_load(&dev->quota[type]);
#endif
}
/****************************************************************************
@ -1405,16 +1359,16 @@ FAR netpkt_t *netpkt_alloc(FAR struct netdev_lowerhalf_s *dev,
{
FAR netpkt_t *pkt;
if (quota_fetch_dec(dev, type) <= 0)
if (atomic_fetch_sub(&dev->quota[type], 1) <= 0)
{
quota_fetch_inc(dev, type);
atomic_fetch_add(&dev->quota[type], 1);
return NULL;
}
pkt = iob_tryalloc(false);
if (pkt == NULL)
{
quota_fetch_inc(dev, type);
atomic_fetch_add(&dev->quota[type], 1);
return NULL;
}
@ -1438,7 +1392,7 @@ FAR netpkt_t *netpkt_alloc(FAR struct netdev_lowerhalf_s *dev,
void netpkt_free(FAR struct netdev_lowerhalf_s *dev, FAR netpkt_t *pkt,
enum netpkt_type_e type)
{
quota_fetch_inc(dev, type);
atomic_fetch_add(&dev->quota[type], 1);
iob_free_chain(pkt);
}

View file

@ -69,16 +69,6 @@
# define CONFIG_DESIGNATED_INITIALIZERS 1
#endif
/* ISO C/C++11 atomic types support */
#undef CONFIG_HAVE_ATOMICS
#if ((defined(__cplusplus) && __cplusplus >= 201103L) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)) && \
!defined(__STDC_NO_ATOMICS__)
# define CONFIG_HAVE_ATOMICS
#endif
/* C++ support */
#undef CONFIG_HAVE_CXX14

View file

@ -30,14 +30,11 @@
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <nuttx/spinlock.h>
#include <nuttx/atomic.h>
#include <net/if.h>
#include <netinet/in.h>
#ifdef CONFIG_HAVE_ATOMICS
# include <stdatomic.h>
#endif
#include <nuttx/net/ip.h>
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
@ -120,12 +117,7 @@ struct netdev_lowerhalf_s
/* Max # of buffer held by driver */
#ifdef CONFIG_HAVE_ATOMICS
atomic_int quota[NETPKT_TYPENUM];
#else
int quota[NETPKT_TYPENUM];
spinlock_t lock;
#endif
/* The structure used by net stack.
* Note: Do not change its fields unless you know what you are doing.

View file

@ -67,8 +67,7 @@ LIBMETAL_HDRS_SEDEXP := \
s/@PROJECT_SYSTEM_UPPER@/nuttx/g; \
s/@PROJECT_PROCESSOR_UPPER@/$(LIBMETAL_ARCH)/g; \
s/@PROJECT_MACHINE_UPPER@/$(CONFIG_ARCH_CHIP)/g; \
s/cmakedefine HAVE_STDATOMIC_H/include <nuttx\/compiler.h>/g; \
s/defined(HAVE_STDATOMIC_H)/defined(CONFIG_HAVE_ATOMICS)/g; \
s/cmakedefine HAVE_STDATOMIC_H/define HAVE_STDATOMIC_H/g; \
s/cmakedefine/undef/g"
ifeq ($(wildcard libmetal/.git),)