From dcea1b90e733fdd7f6a07bc8614c35bee41687d0 Mon Sep 17 00:00:00 2001 From: zhangyuan29 Date: Wed, 20 Nov 2024 20:53:28 +0800 Subject: [PATCH] arch_atomic: only support atomic_xx and atomic64_xx function Modify the kernel to use only atomic_xx and atomic64_xx interfaces, avoiding the use of sizeof or typeof to determine the type of atomic operations, thereby simplifying the kernel's atomic interface operations. Signed-off-by: zhangyuan29 --- arch/arm/src/cxd56xx/cxd56_sph.c | 2 +- arch/arm/src/cxd56xx/cxd56_uart0.c | 4 +- arch/sim/src/sim/sim_heap.c | 24 +-- drivers/i3c/master.c | 6 +- drivers/input/aw86225.c | 14 +- drivers/input/aw86225_internal.h | 6 +- drivers/net/netdev_upperhalf.c | 4 +- drivers/note/notesnap_driver.c | 10 +- drivers/reset/core.c | 10 +- drivers/rpmsg/rpmsg_port.h | 6 +- drivers/rpmsg/rpmsg_port_spi.c | 4 +- drivers/rpmsg/rpmsg_port_spi_slave.c | 6 +- drivers/serial/pty.c | 2 +- drivers/serial/uart_ram.c | 32 +-- drivers/wireless/bluetooth/bt_bridge.c | 2 +- drivers/wireless/bluetooth/bt_slip.c | 2 +- fs/inode/fs_inoderemove.c | 2 +- fs/inode/fs_inodereserve.c | 2 +- fs/mqueue/mq_open.c | 2 +- fs/mqueue/mq_unlink.c | 2 +- fs/shm/shmfs.c | 4 +- fs/vfs/fs_pseudofile.c | 2 +- include/nuttx/atomic.h | 203 ++++++++++++++---- include/nuttx/fs/fs.h | 2 +- include/nuttx/i3c/master.h | 4 +- include/nuttx/lib/stdatomic.h | 278 ------------------------- include/nuttx/net/netdev_lowerhalf.h | 2 +- include/nuttx/reset/reset.h | 6 +- include/nuttx/serial/uart_ram.h | 4 +- include/nuttx/spinlock.h | 55 ++--- include/nuttx/spinlock_type.h | 19 +- libs/libc/machine/arch_atomic.c | 92 ++------ libs/libc/misc/lib_fdsan.c | 2 +- wireless/bluetooth/bt_atomic.h | 8 +- 34 files changed, 295 insertions(+), 528 deletions(-) delete mode 100644 include/nuttx/lib/stdatomic.h diff --git a/arch/arm/src/cxd56xx/cxd56_sph.c b/arch/arm/src/cxd56xx/cxd56_sph.c index 72e6b0cbb2..a1bd1bdfde 100644 --- a/arch/arm/src/cxd56xx/cxd56_sph.c +++ b/arch/arm/src/cxd56xx/cxd56_sph.c @@ -104,7 +104,7 @@ static int sph_open(struct file *filep) { /* Exclusive access */ - if (atomic_load(&filep->f_inode->i_crefs) > 2) + if (atomic_read(&filep->f_inode->i_crefs) > 2) { return ERROR; } diff --git a/arch/arm/src/cxd56xx/cxd56_uart0.c b/arch/arm/src/cxd56xx/cxd56_uart0.c index c0eeb97125..d34d620b39 100644 --- a/arch/arm/src/cxd56xx/cxd56_uart0.c +++ b/arch/arm/src/cxd56xx/cxd56_uart0.c @@ -115,7 +115,7 @@ static int uart0_open(struct file *filep) int stop; int ret; - if (atomic_load(&inode->i_crefs) > 2) + if (atomic_read(&inode->i_crefs) > 2) { return OK; } @@ -172,7 +172,7 @@ static int uart0_close(struct file *filep) { struct inode *inode = filep->f_inode; - if (atomic_load(&inode->i_crefs) == 2) + if (atomic_read(&inode->i_crefs) == 2) { fw_pd_uartdisable(0); fw_pd_uartuninit(0); diff --git a/arch/sim/src/sim/sim_heap.c b/arch/sim/src/sim/sim_heap.c index 1113b8c352..87db535d8d 100644 --- a/arch/sim/src/sim/sim_heap.c +++ b/arch/sim/src/sim/sim_heap.c @@ -60,9 +60,9 @@ struct mm_heap_s size_t mm_delaycount[CONFIG_SMP_NCPUS]; #endif - atomic_int aordblks; - atomic_int uordblks; - atomic_int usmblks; + atomic_t aordblks; + atomic_t uordblks; + atomic_t usmblks; #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) struct procfs_meminfo_entry_s mm_procfs; @@ -387,7 +387,7 @@ void *mm_realloc(struct mm_heap_s *heap, void *oldmem, atomic_fetch_add(&heap->aordblks, oldmem == NULL && mem != NULL); newsize = host_mallocsize(mem ? mem : oldmem); atomic_fetch_add(&heap->uordblks, newsize); - usmblks = atomic_load(&heap->usmblks); + usmblks = atomic_read(&heap->usmblks); if (mem != NULL) { if (oldmem != NULL) @@ -400,13 +400,13 @@ void *mm_realloc(struct mm_heap_s *heap, void *oldmem, do { - uordblks = atomic_load(&heap->uordblks); + uordblks = atomic_read(&heap->uordblks); if (uordblks <= usmblks) { break; } } - while (atomic_compare_exchange_weak(&heap->usmblks, &usmblks, uordblks)); + while (atomic_try_cmpxchg(&heap->usmblks, &usmblks, uordblks)); #if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0 if (mem == NULL && free_delaylist(heap, true)) @@ -490,17 +490,17 @@ void *mm_memalign(struct mm_heap_s *heap, size_t alignment, size_t size) sched_note_heap(NOTE_HEAP_ALLOC, heap, mem, size, 0); atomic_fetch_add(&heap->aordblks, 1); atomic_fetch_add(&heap->uordblks, size); - usmblks = atomic_load(&heap->usmblks); + usmblks = atomic_read(&heap->usmblks); do { - uordblks = atomic_load(&heap->uordblks); + uordblks = atomic_read(&heap->uordblks); if (uordblks <= usmblks) { break; } } - while (atomic_compare_exchange_weak(&heap->usmblks, &usmblks, uordblks)); + while (atomic_try_cmpxchg(&heap->usmblks, &usmblks, uordblks)); #if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0 if (mem == NULL && free_delaylist(heap, true)) @@ -575,9 +575,9 @@ struct mallinfo mm_mallinfo(struct mm_heap_s *heap) struct mallinfo info; memset(&info, 0, sizeof(struct mallinfo)); - info.aordblks = atomic_load(&heap->aordblks); - info.uordblks = atomic_load(&heap->uordblks); - info.usmblks = atomic_load(&heap->usmblks); + info.aordblks = atomic_read(&heap->aordblks); + info.uordblks = atomic_read(&heap->uordblks); + info.usmblks = atomic_read(&heap->usmblks); return info; } diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index f2d3c452fa..40ab0a763b 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1181,7 +1181,7 @@ static void i3c_master_handle_ibi(FAR void *arg) master->ops->recycle_ibi_slot(dev, slot); atomic_fetch_sub(&dev->ibi->pending_ibis, 1); - if (!atomic_load(&dev->ibi->pending_ibis)) + if (!atomic_read(&dev->ibi->pending_ibis)) { sem_post(&dev->ibi->all_ibis_handled); } @@ -2034,7 +2034,7 @@ int i3c_dev_disable_ibi_locked(FAR struct i3c_dev_desc *dev) return ret; } - if (atomic_load(&dev->ibi->pending_ibis)) + if (atomic_read(&dev->ibi->pending_ibis)) { sem_wait(&dev->ibi->all_ibis_handled); } @@ -2087,7 +2087,7 @@ int i3c_dev_request_ibi_locked(FAR struct i3c_dev_desc *dev, return -ENOMEM; } - atomic_init(&ibi->pending_ibis, 0); + atomic_set(&ibi->pending_ibis, 0); sem_init(&ibi->all_ibis_handled, 0, 1); ibi->handler = req->handler; ibi->max_payload_len = req->max_payload_len; diff --git a/drivers/input/aw86225.c b/drivers/input/aw86225.c index 24fb868fb8..c93d2f48a7 100644 --- a/drivers/input/aw86225.c +++ b/drivers/input/aw86225.c @@ -956,7 +956,7 @@ static int aw86225_haptic_rtp_init(FAR struct aw86225 *aw86225) nxmutex_lock(&aw86225->rtp_lock); while ((!aw86225_haptic_rtp_get_fifo_afs(aw86225)) && (aw86225->play_mode == AW86225_HAPTIC_RTP_MODE) - && !atomic_load(&aw86225->exit_in_rtp_loop)) + && !atomic_read(&aw86225->exit_in_rtp_loop)) { if (!aw86225->rtp_container) { @@ -1014,7 +1014,7 @@ static int aw86225_haptic_rtp_init(FAR struct aw86225 *aw86225) nxmutex_unlock(&aw86225->rtp_lock); if (aw86225->play_mode == AW86225_HAPTIC_RTP_MODE - && !atomic_load(&aw86225->exit_in_rtp_loop)) + && !atomic_read(&aw86225->exit_in_rtp_loop)) { aw86225_haptic_set_rtp_aei(aw86225, true); } @@ -1121,8 +1121,8 @@ static void aw86225_rtp_work_routine(FAR void *arg) /* wait for irq to exit */ - atomic_store(&aw86225->exit_in_rtp_loop, 1); - while (atomic_load(&aw86225->is_in_rtp_loop)) + atomic_set(&aw86225->exit_in_rtp_loop, 1); + while (atomic_read(&aw86225->is_in_rtp_loop)) { iinfo("%s: goint to waiting irq exit\n", __func__); @@ -1130,7 +1130,7 @@ static void aw86225_rtp_work_routine(FAR void *arg) if (ret == -ERESTART) { - atomic_store(&aw86225->exit_in_rtp_loop, 0); + atomic_set(&aw86225->exit_in_rtp_loop, 0); nxsem_post(&aw86225->stop_wait_q); nxmutex_unlock(&aw86225->lock); ierr("%s: wake up by signal return erro\n", __func__); @@ -1138,7 +1138,7 @@ static void aw86225_rtp_work_routine(FAR void *arg) } } - atomic_store(&aw86225->exit_in_rtp_loop, 0); + atomic_set(&aw86225->exit_in_rtp_loop, 0); nxsem_post(&aw86225->stop_wait_q); aw86225_haptic_stop(aw86225); @@ -2155,7 +2155,7 @@ static int aw86225_haptics_upload_effect(FAR struct ff_lowerhalf_s *lower, aw86225->effect_type = effect->type; nxmutex_lock(&aw86225->lock); - while (atomic_load(&aw86225->exit_in_rtp_loop)) + while (atomic_read(&aw86225->exit_in_rtp_loop)) { iinfo("%s: goint to waiting rtp exit\n", __func__); nxmutex_unlock(&aw86225->lock); diff --git a/drivers/input/aw86225_internal.h b/drivers/input/aw86225_internal.h index 1dda28f179..dd32251dfd 100644 --- a/drivers/input/aw86225_internal.h +++ b/drivers/input/aw86225_internal.h @@ -29,10 +29,10 @@ #include -#include #include #include +#include #include #include #include @@ -287,8 +287,8 @@ struct aw86225 unsigned char level; unsigned int osc_cali_run; unsigned char ram_vbat_comp; - atomic_int is_in_rtp_loop; - atomic_int exit_in_rtp_loop; + atomic_t is_in_rtp_loop; + atomic_t exit_in_rtp_loop; sem_t wait_q; sem_t stop_wait_q; }; diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c index cf5f65223e..4a3132efeb 100644 --- a/drivers/net/netdev_upperhalf.c +++ b/drivers/net/netdev_upperhalf.c @@ -1369,7 +1369,7 @@ void netdev_lower_txdone(FAR struct netdev_lowerhalf_s *dev) * Name: netdev_lower_quota_load * * Description: - * Fetch the quota, works like atomic_load. + * Fetch the quota, works like atomic_read. * * Input Parameters: * dev - The lower half device driver structure @@ -1380,7 +1380,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) { - return atomic_load(&dev->quota[type]); + return atomic_read(&dev->quota[type]); } /**************************************************************************** diff --git a/drivers/note/notesnap_driver.c b/drivers/note/notesnap_driver.c index 50b5182761..441992fa15 100644 --- a/drivers/note/notesnap_driver.c +++ b/drivers/note/notesnap_driver.c @@ -50,8 +50,8 @@ struct notesnap_s { struct note_driver_s driver; struct notifier_block nb; - atomic_int index; - atomic_bool dumping; + atomic_t index; + atomic_t dumping; struct notesnap_chunk_s buffer[CONFIG_DRIVERS_NOTESNAP_NBUFFERS]; }; @@ -212,7 +212,7 @@ static inline void notesnap_common(FAR struct note_driver_s *drv, FAR struct notesnap_chunk_s *note; size_t index; - if (atomic_load(&snap->dumping)) + if (atomic_read(&snap->dumping)) { return; } @@ -388,7 +388,7 @@ void notesnap_dump_with_stream(FAR struct lib_outstream_s *stream) /* Stop recording while dumping */ - atomic_store(&g_notesnap.dumping, true); + atomic_set(&g_notesnap.dumping, true); for (i = 0; i < CONFIG_DRIVERS_NOTESNAP_NBUFFERS; i++) { @@ -411,7 +411,7 @@ void notesnap_dump_with_stream(FAR struct lib_outstream_s *stream) note->pid, g_notesnap_type[note->type], note->args); } - atomic_store(&g_notesnap.dumping, false); + atomic_set(&g_notesnap.dumping, false); } /**************************************************************************** diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 23193f1cde..aa852c2e32 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -310,7 +310,7 @@ reset_control_get_internal(FAR struct reset_controller_dev *rcdev, rstc->rcdev = rcdev; list_add_after(&rcdev->reset_control_head, &rstc->list); rstc->id = index; - atomic_init(&rstc->refcnt, 1); + atomic_set(&rstc->refcnt, 1); rstc->acquired = acquired; rstc->shared = shared; @@ -528,7 +528,7 @@ int reset_control_reset(FAR struct reset_control *rstc) if (rstc->shared) { - if (atomic_load(&rstc->deassert_count) != 0) + if (atomic_read(&rstc->deassert_count) != 0) { return -EINVAL; } @@ -598,12 +598,12 @@ int reset_control_assert(FAR struct reset_control *rstc) if (rstc->shared) { - if (atomic_load(&rstc->triggered_count) != 0) + if (atomic_read(&rstc->triggered_count) != 0) { return -EINVAL; } - if (atomic_load(&rstc->deassert_count) == 0) + if (atomic_read(&rstc->deassert_count) == 0) { rsterr("deassert_count = 0, invalid value\n"); return -EINVAL; @@ -682,7 +682,7 @@ int reset_control_deassert(FAR struct reset_control *rstc) if (rstc->shared) { - if (atomic_load(&rstc->triggered_count) != 0) + if (atomic_read(&rstc->triggered_count) != 0) { rsterr("triggered_count != 0, invalid value\n"); return -EINVAL; diff --git a/drivers/rpmsg/rpmsg_port.h b/drivers/rpmsg/rpmsg_port.h index 9e55058694..e46edc39c1 100644 --- a/drivers/rpmsg/rpmsg_port.h +++ b/drivers/rpmsg/rpmsg_port.h @@ -29,7 +29,7 @@ #include -#include +#include #include #include @@ -237,7 +237,7 @@ void rpmsg_port_queue_add_buffer(FAR struct rpmsg_port_queue_s *queue, static inline_function uint16_t rpmsg_port_queue_navail(FAR struct rpmsg_port_queue_s *queue) { - return atomic_load(&queue->free.num); + return atomic_read(&queue->free.num); } /**************************************************************************** @@ -257,7 +257,7 @@ uint16_t rpmsg_port_queue_navail(FAR struct rpmsg_port_queue_s *queue) static inline_function uint16_t rpmsg_port_queue_nused(FAR struct rpmsg_port_queue_s *queue) { - return atomic_load(&queue->ready.num); + return atomic_read(&queue->ready.num); } /**************************************************************************** diff --git a/drivers/rpmsg/rpmsg_port_spi.c b/drivers/rpmsg/rpmsg_port_spi.c index 9552339f77..67a2f4cc22 100644 --- a/drivers/rpmsg/rpmsg_port_spi.c +++ b/drivers/rpmsg/rpmsg_port_spi.c @@ -95,7 +95,7 @@ struct rpmsg_port_spi_s uint16_t rxavail; uint16_t rxthres; - atomic_int transferring; + atomic_t transferring; }; /**************************************************************************** @@ -300,7 +300,7 @@ static void rpmsg_port_spi_complete_handler(FAR void *arg) } out: - if (atomic_exchange(&rpspi->transferring, 0) > 1) + if (atomic_xchg(&rpspi->transferring, 0) > 1) { rpmsg_port_spi_exchange(rpspi); } diff --git a/drivers/rpmsg/rpmsg_port_spi_slave.c b/drivers/rpmsg/rpmsg_port_spi_slave.c index 609252c6b3..ad49a74752 100644 --- a/drivers/rpmsg/rpmsg_port_spi_slave.c +++ b/drivers/rpmsg/rpmsg_port_spi_slave.c @@ -26,9 +26,9 @@ #include #include -#include #include +#include #include #include #include @@ -97,7 +97,7 @@ struct rpmsg_port_spi_s uint16_t rxavail; uint16_t rxthres; - atomic_int transferring; + atomic_t transferring; }; /**************************************************************************** @@ -369,7 +369,7 @@ static void rpmsg_port_spi_slave_notify(FAR struct spi_slave_dev_s *dev, } out: - if (atomic_exchange(&rpspi->transferring, 0) > 1 || + if (atomic_xchg(&rpspi->transferring, 0) > 1 || (rpspi->txavail > 0 && rpmsg_port_queue_nused(&rpspi->port.txq) > 0)) { rpmsg_port_spi_exchange(rpspi); diff --git a/drivers/serial/pty.c b/drivers/serial/pty.c index 11e7855424..4b04b2fd7b 100644 --- a/drivers/serial/pty.c +++ b/drivers/serial/pty.c @@ -340,7 +340,7 @@ static int pty_close(FAR struct file *filep) /* Check if the decremented inode reference count would go to zero */ - if (atomic_load(&inode->i_crefs) == 1) + if (atomic_read(&inode->i_crefs) == 1) { /* Did the (single) master just close its reference? */ diff --git a/drivers/serial/uart_ram.c b/drivers/serial/uart_ram.c index a0042bfb0e..c4124a9e1e 100644 --- a/drivers/serial/uart_ram.c +++ b/drivers/serial/uart_ram.c @@ -229,8 +229,8 @@ static struct uart_ram_s g_uart_ram2 = static size_t uart_rambuf_txready(FAR struct uart_rambuf_s *buf) { - atomic_uint wroff = atomic_load(&buf->wroff); - atomic_uint rdoff = atomic_load(&buf->rdoff); + int wroff = atomic_read(&buf->wroff); + int rdoff = atomic_read(&buf->rdoff); return rdoff > wroff ? rdoff - wroff - 1 : sizeof(buf->buffer) - wroff + rdoff - 1; } @@ -241,8 +241,8 @@ static size_t uart_rambuf_txready(FAR struct uart_rambuf_s *buf) static size_t uart_rambuf_rxavailable(FAR struct uart_rambuf_s *buf) { - atomic_uint wroff = atomic_load(&buf->wroff); - atomic_uint rdoff = atomic_load(&buf->rdoff); + int wroff = atomic_read(&buf->wroff); + int rdoff = atomic_read(&buf->rdoff); return wroff >= rdoff ? wroff - rdoff : sizeof(buf->buffer) - rdoff + wroff; @@ -303,19 +303,19 @@ static int uart_ram_ioctl(FAR struct file *filep, int cmd, unsigned long arg) static int uart_ram_receive(FAR struct uart_dev_s *dev, FAR uint32_t *status) { FAR struct uart_ram_s *priv = dev->priv; - atomic_uint rdoff; + int rdoff; int ch; while (!uart_rambuf_rxavailable(priv->rx)); - rdoff = atomic_load(&priv->rx->rdoff); + rdoff = atomic_read(&priv->rx->rdoff); ch = priv->rx->buffer[rdoff]; if (++rdoff >= sizeof(priv->rx->buffer)) { rdoff = 0; } - atomic_store(&priv->rx->rdoff, rdoff); + atomic_set(&priv->rx->rdoff, rdoff); *status = 0; return ch; @@ -347,7 +347,7 @@ static void uart_ram_dmasend(FAR struct uart_dev_s *dev) { FAR struct uart_ram_s *priv = dev->priv; - atomic_store(&priv->tx->wroff, dev->xmit.head); + atomic_set(&priv->tx->wroff, dev->xmit.head); } /**************************************************************************** @@ -371,7 +371,7 @@ static void uart_ram_dmarxfree(FAR struct uart_dev_s *dev) /* When the dma RX buffer is free, update the read data position */ - atomic_store(&priv->rx->rdoff, dev->recv.tail); + atomic_set(&priv->rx->rdoff, dev->recv.tail); } /**************************************************************************** @@ -393,18 +393,18 @@ static void uart_ram_dmatxavail(FAR struct uart_dev_s *dev) static void uart_ram_send(FAR struct uart_dev_s *dev, int ch) { FAR struct uart_ram_s *priv = dev->priv; - atomic_uint wroff; + int wroff; while (!uart_rambuf_txready(priv->tx)); - wroff = atomic_load(&priv->tx->wroff); + wroff = atomic_read(&priv->tx->wroff); priv->tx->buffer[wroff] = ch; if (++wroff >= sizeof(priv->tx->buffer)) { wroff = 0; } - atomic_store(&priv->tx->wroff, wroff); + atomic_set(&priv->tx->wroff, wroff); } /**************************************************************************** @@ -488,10 +488,10 @@ int uart_ram_register(FAR const char *devname, return -ENOMEM; } - atomic_store(&rambuf[0].wroff, 0); - atomic_store(&rambuf[0].rdoff, 0); - atomic_store(&rambuf[1].wroff, 0); - atomic_store(&rambuf[1].rdoff, 0); + atomic_set(&rambuf[0].wroff, 0); + atomic_set(&rambuf[0].rdoff, 0); + atomic_set(&rambuf[1].wroff, 0); + atomic_set(&rambuf[1].rdoff, 0); if (slave) { diff --git a/drivers/wireless/bluetooth/bt_bridge.c b/drivers/wireless/bluetooth/bt_bridge.c index d53f62cfaa..6e440396a5 100644 --- a/drivers/wireless/bluetooth/bt_bridge.c +++ b/drivers/wireless/bluetooth/bt_bridge.c @@ -75,7 +75,7 @@ struct bt_bridge_s #ifdef CONFIG_BLUETOOTH_BRIDGE_BTSNOOP FAR struct snoop_s *snoop; #endif /* CONFIG_BLUETOOTH_BRIDGE_BTSNOOP */ - atomic_uint refs; + atomic_t refs; bool dispatched[BT_FILTER_CMD_COUNT]; }; diff --git a/drivers/wireless/bluetooth/bt_slip.c b/drivers/wireless/bluetooth/bt_slip.c index b886a4b294..cfbce689f1 100644 --- a/drivers/wireless/bluetooth/bt_slip.c +++ b/drivers/wireless/bluetooth/bt_slip.c @@ -27,12 +27,12 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include diff --git a/fs/inode/fs_inoderemove.c b/fs/inode/fs_inoderemove.c index 792eabe0a5..3b8660e71f 100644 --- a/fs/inode/fs_inoderemove.c +++ b/fs/inode/fs_inoderemove.c @@ -136,7 +136,7 @@ int inode_remove(FAR const char *path) * to it */ - if (atomic_load(&inode->i_crefs)) + if (atomic_read(&inode->i_crefs)) { return -EBUSY; } diff --git a/fs/inode/fs_inodereserve.c b/fs/inode/fs_inodereserve.c index 35fae49dd7..8cd41a5b18 100644 --- a/fs/inode/fs_inodereserve.c +++ b/fs/inode/fs_inodereserve.c @@ -88,7 +88,7 @@ static FAR struct inode *inode_alloc(FAR const char *name, mode_t mode) if (inode) { inode->i_ino = g_ino++; - atomic_init(&inode->i_crefs, 1); + atomic_set(&inode->i_crefs, 1); #ifdef CONFIG_PSEUDOFS_ATTRIBUTES inode->i_mode = mode; clock_gettime(CLOCK_REALTIME, &inode->i_atime); diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c index d2e5cc79bc..402ed9a5d1 100644 --- a/fs/mqueue/mq_open.c +++ b/fs/mqueue/mq_open.c @@ -76,7 +76,7 @@ static int nxmq_file_close(FAR struct file *filep) { FAR struct inode *inode = filep->f_inode; - if (atomic_load(&inode->i_crefs) <= 0) + if (atomic_read(&inode->i_crefs) <= 0) { FAR struct mqueue_inode_s *msgq = inode->i_private; diff --git a/fs/mqueue/mq_unlink.c b/fs/mqueue/mq_unlink.c index fb4d9d1550..cc32de0b56 100644 --- a/fs/mqueue/mq_unlink.c +++ b/fs/mqueue/mq_unlink.c @@ -58,7 +58,7 @@ static void mq_inode_release(FAR struct inode *inode) { - if (atomic_load(&inode->i_crefs) <= 1) + if (atomic_read(&inode->i_crefs) <= 1) { FAR struct mqueue_inode_s *msgq = inode->i_private; diff --git a/fs/shm/shmfs.c b/fs/shm/shmfs.c index 752e2d5dac..e1cc39a539 100644 --- a/fs/shm/shmfs.c +++ b/fs/shm/shmfs.c @@ -186,7 +186,7 @@ static int shmfs_release(FAR struct inode *inode) * The inode is released after this call, hence checking if i_crefs <= 1. */ - if (inode->i_parent == NULL && atomic_load(&inode->i_crefs) <= 1) + if (inode->i_parent == NULL && atomic_read(&inode->i_crefs) <= 1) { shmfs_free_object(inode->i_private); inode->i_private = NULL; @@ -256,7 +256,7 @@ static int shmfs_truncate(FAR struct file *filep, off_t length) #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS static int shmfs_unlink(FAR struct inode *inode) { - if (atomic_load(&inode->i_crefs) <= 1) + if (atomic_read(&inode->i_crefs) <= 1) { shmfs_free_object(inode->i_private); inode->i_private = NULL; diff --git a/fs/vfs/fs_pseudofile.c b/fs/vfs/fs_pseudofile.c index 314c79eed8..df896a5078 100644 --- a/fs/vfs/fs_pseudofile.c +++ b/fs/vfs/fs_pseudofile.c @@ -354,7 +354,7 @@ static int pseudofile_munmap(FAR struct task_group_s *group, */ if (inode->i_parent == NULL && - atomic_load(&inode->i_crefs) <= 1) + atomic_read(&inode->i_crefs) <= 1) { /* Delete the inode metadata */ diff --git a/include/nuttx/atomic.h b/include/nuttx/atomic.h index 1c430f963f..7fee0f75da 100644 --- a/include/nuttx/atomic.h +++ b/include/nuttx/atomic.h @@ -27,72 +27,160 @@ * Included Files ****************************************************************************/ +#include + #ifdef __has_include -# if defined(__cplusplus) && __has_include() +# if __has_include() && defined(__cplusplus) extern "C++" { # include +# define ATOMIC_FUNC(f, n) atomic_##f##_explicit -# define ATOMIC_VAR_INIT(value) (value) - - using std::memory_order; - using std::atomic_bool; - using std::atomic_char; - using std::atomic_schar; - using std::atomic_uchar; - using std::atomic_short; - using std::atomic_ushort; - using std::atomic_int; - using std::atomic_uint; - using std::atomic_long; - using std::atomic_ulong; - using std::atomic_llong; - using std::atomic_ullong; - - using std::atomic_load; using std::atomic_load_explicit; - using std::atomic_store; using std::atomic_store_explicit; - using std::atomic_exchange; using std::atomic_exchange_explicit; - using std::atomic_compare_exchange_strong; using std::atomic_compare_exchange_strong_explicit; - using std::atomic_compare_exchange_weak; using std::atomic_compare_exchange_weak_explicit; - using std::atomic_flag_test_and_set; - using std::atomic_flag_test_and_set_explicit; - using std::atomic_flag_clear; - using std::atomic_flag_clear_explicit; - using std::atomic_fetch_add; using std::atomic_fetch_add_explicit; - using std::atomic_fetch_sub; using std::atomic_fetch_sub_explicit; - using std::atomic_fetch_and; using std::atomic_fetch_and_explicit; - using std::atomic_fetch_or; using std::atomic_fetch_or_explicit; - using std::atomic_fetch_xor; using std::atomic_fetch_xor_explicit; + + typedef volatile int32_t atomic_t; + typedef volatile int64_t atomic64_t; } # elif __has_include() && \ ((defined(__cplusplus) && __cplusplus >= 201103L) || \ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)) && \ !defined(__STDC_NO_ATOMICS__) -# if !(__clang__) && defined(__cplusplus) +# if !defined(__clang__) && defined(__cplusplus) # define _Atomic # endif -# include # include -# ifndef ATOMIC_VAR_INIT -# define ATOMIC_VAR_INIT(value) (value) -# endif -# else -# include +# define ATOMIC_FUNC(f, n) atomic_##f##_explicit + + typedef volatile _Atomic int32_t atomic_t; + typedef volatile _Atomic int64_t atomic64_t; # endif -#else -# include #endif +#ifndef ATOMIC_FUNC +# define __ATOMIC_RELAXED 0 +# define __ATOMIC_CONSUME 1 +# define __ATOMIC_ACQUIRE 2 +# define __ATOMIC_RELEASE 3 +# define __ATOMIC_ACQ_REL 4 +# define __ATOMIC_SEQ_CST 5 + +# define ATOMIC_FUNC(f, n) nx_atomic_##f##_##n + +# define atomic_fetch_add(obj, val) ATOMIC_FUNC(fetch_add, 4)(obj, val, __ATOMIC_ACQ_REL) +# define atomic_fetch_sub(obj, val) ATOMIC_FUNC(fetch_sub, 4)(obj, val, __ATOMIC_ACQ_REL) +# define atomic_fetch_and(obj, val) ATOMIC_FUNC(fetch_and, 4)(obj, val, __ATOMIC_ACQ_REL) +# define atomic_fetch_or(obj, val) ATOMIC_FUNC(fetch_or, 4)(obj, val, __ATOMIC_ACQ_REL) +# define atomic_fetch_xor(obj, val) ATOMIC_FUNC(fetch_xor, 4)(obj, val, __ATOMIC_ACQ_REL) + +typedef volatile int32_t atomic_t; +typedef volatile int64_t atomic64_t; +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define atomic_set(obj, val) ATOMIC_FUNC(store, 4)(obj, val, __ATOMIC_RELAXED) +#define atomic_set_release(obj, val) ATOMIC_FUNC(store, 4)(obj, val, __ATOMIC_RELEASE) +#define atomic64_set(obj, val) ATOMIC_FUNC(store, 8)(obj, val, __ATOMIC_RELAXED) +#define atomic64_set_release(obj, val) ATOMIC_FUNC(store, 8)(obj, val, __ATOMIC_RELEASE) + +#define atomic_read(obj) ATOMIC_FUNC(load, 4)(obj, __ATOMIC_RELAXED) +#define atomic_read_acquire(obj) ATOMIC_FUNC(load, 4)(obj, __ATOMIC_ACQUIRE) +#define atomic64_read(obj) ATOMIC_FUNC(load, 8)(obj, __ATOMIC_RELAXED) +#define atomic64_read_acquire(obj) ATOMIC_FUNC(load, 8)(obj, __ATOMIC_ACQUIRE) + +#define atomic_fetch_add_acquire(obj, val) ATOMIC_FUNC(fetch_add, 4)(obj, val, __ATOMIC_ACQUIRE) +#define atomic_fetch_add_release(obj, val) ATOMIC_FUNC(fetch_add, 4)(obj, val, __ATOMIC_RELEASE) +#define atomic_fetch_add_relaxed(obj, val) ATOMIC_FUNC(fetch_add, 4)(obj, val, __ATOMIC_RELAXED) +#define atomic64_fetch_add(obj, val) ATOMIC_FUNC(fetch_add, 8)(obj, val, __ATOMIC_ACQ_REL) +#define atomic64_fetch_add_acquire(obj, val) ATOMIC_FUNC(fetch_add, 8)(obj, val, __ATOMIC_ACQUIRE) +#define atomic64_fetch_add_release(obj, val) ATOMIC_FUNC(fetch_add, 8)(obj, val, __ATOMIC_RELEASE) +#define atomic64_fetch_add_relaxed(obj, val) ATOMIC_FUNC(fetch_add, 8)(obj, val, __ATOMIC_RELAXED) + +#define atomic_fetch_sub_acquire(obj, val) ATOMIC_FUNC(fetch_sub, 4)(obj, val, __ATOMIC_ACQUIRE) +#define atomic_fetch_sub_release(obj, val) ATOMIC_FUNC(fetch_sub, 4)(obj, val, __ATOMIC_RELEASE) +#define atomic_fetch_sub_relaxed(obj, val) ATOMIC_FUNC(fetch_sub, 4)(obj, val, __ATOMIC_RELAXED) +#define atomic64_fetch_sub(obj, val) ATOMIC_FUNC(fetch_sub, 8)(obj, val, __ATOMIC_ACQ_REL) +#define atomic64_fetch_sub_acquire(obj, val) ATOMIC_FUNC(fetch_sub, 8)(obj, val, __ATOMIC_ACQUIRE) +#define atomic64_fetch_sub_release(obj, val) ATOMIC_FUNC(fetch_sub, 8)(obj, val, __ATOMIC_RELEASE) +#define atomic64_fetch_sub_relaxed(obj, val) ATOMIC_FUNC(fetch_sub, 8)(obj, val, __ATOMIC_RELAXED) + +#define atomic_fetch_and_acquire(obj, val) ATOMIC_FUNC(fetch_and, 4)(obj, val, __ATOMIC_ACQUIRE) +#define atomic_fetch_and_release(obj, val) ATOMIC_FUNC(fetch_and, 4)(obj, val, __ATOMIC_RELEASE) +#define atomic_fetch_and_relaxed(obj, val) ATOMIC_FUNC(fetch_and, 4)(obj, val, __ATOMIC_RELAXED) +#define atomic64_fetch_and(obj, val) ATOMIC_FUNC(fetch_and, 8)(obj, val, __ATOMIC_ACQ_REL) +#define atomic64_fetch_and_acquire(obj, val) ATOMIC_FUNC(fetch_and, 8)(obj, val, __ATOMIC_ACQUIRE) +#define atomic64_fetch_and_release(obj, val) ATOMIC_FUNC(fetch_and, 8)(obj, val, __ATOMIC_RELEASE) +#define atomic64_fetch_and_relaxed(obj, val) ATOMIC_FUNC(fetch_and, 8)(obj, val, __ATOMIC_RELAXED) + +#define atomic_fetch_or_acquire(obj, val) ATOMIC_FUNC(fetch_or, 4)(obj, val, __ATOMIC_ACQUIRE) +#define atomic_fetch_or_release(obj, val) ATOMIC_FUNC(fetch_or, 4)(obj, val, __ATOMIC_RELEASE) +#define atomic_fetch_or_relaxed(obj, val) ATOMIC_FUNC(fetch_or, 4)(obj, val, __ATOMIC_RELAXED) +#define atomic64_fetch_or(obj, val) ATOMIC_FUNC(fetch_or, 8)(obj, val, __ATOMIC_ACQ_REL) +#define atomic64_fetch_or_acquire(obj, val) ATOMIC_FUNC(fetch_or, 8)(obj, val, __ATOMIC_ACQUIRE) +#define atomic64_fetch_or_release(obj, val) ATOMIC_FUNC(fetch_or, 8)(obj, val, __ATOMIC_RELEASE) +#define atomic64_fetch_or_relaxed(obj, val) ATOMIC_FUNC(fetch_or, 8)(obj, val, __ATOMIC_RELAXED) + +#define atomic_fetch_xor_acquire(obj, val) ATOMIC_FUNC(fetch_xor, 4)(obj, val, __ATOMIC_ACQUIRE) +#define atomic_fetch_xor_release(obj, val) ATOMIC_FUNC(fetch_xor, 4)(obj, val, __ATOMIC_RELEASE) +#define atomic_fetch_xor_relaxed(obj, val) ATOMIC_FUNC(fetch_xor, 4)(obj, val, __ATOMIC_RELAXED) +#define atomic64_fetch_xor(obj, val) ATOMIC_FUNC(fetch_xor, 8)(obj, val, __ATOMIC_ACQ_REL) +#define atomic64_fetch_xor_acquire(obj, val) ATOMIC_FUNC(fetch_xor, 8)(obj, val, __ATOMIC_ACQUIRE) +#define atomic64_fetch_xor_release(obj, val) ATOMIC_FUNC(fetch_xor, 8)(obj, val, __ATOMIC_RELEASE) +#define atomic64_fetch_xor_relaxed(obj, val) ATOMIC_FUNC(fetch_xor, 8)(obj, val, __ATOMIC_RELAXED) + +#define atomic_xchg(obj, val) ATOMIC_FUNC(exchange, 4)(obj, val, __ATOMIC_ACQ_REL) +#define atomic_xchg_acquire(obj, val) ATOMIC_FUNC(exchange, 4)(obj, val, __ATOMIC_ACQUIRE) +#define atomic_xchg_release(obj, val) ATOMIC_FUNC(exchange, 4)(obj, val, __ATOMIC_RELEASE) +#define atomic_xchg_relaxed(obj, val) ATOMIC_FUNC(exchange, 4)(obj, val, __ATOMIC_RELAXED) +#define atomic64_xchg(obj, val) ATOMIC_FUNC(exchange, 8)(obj, val, __ATOMIC_ACQ_REL) +#define atomic64_xchg_acquire(obj, val) ATOMIC_FUNC(exchange, 8)(obj, val, __ATOMIC_ACQUIRE) +#define atomic64_xchg_release(obj, val) ATOMIC_FUNC(exchange, 8)(obj, val, __ATOMIC_RELEASE) +#define atomic64_xchg_relaxed(obj, val) ATOMIC_FUNC(exchange, 8)(obj, val, __ATOMIC_RELAXED) + +#define atomic_cmpxchg(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_strong, 4)(obj, expected, desired, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED) +#define atomic_cmpxchg_acquire(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_strong, 4)(obj, expected, desired, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED) +#define atomic_cmpxchg_release(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_strong, 4)(obj, expected, desired, __ATOMIC_RELEASE, __ATOMIC_RELAXED) +#define atomic_cmpxchg_relaxed(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_strong, 4)(obj, expected, desired, __ATOMIC_RELAXED, __ATOMIC_RELAXED) +#define atomic_try_cmpxchg(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_weak, 4)(obj, expected, desired, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED) +#define atomic_try_cmpxchg_acquire(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_weak, 4)(obj, expected, desired, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED) +#define atomic_try_cmpxchg_release(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_weak, 4)(obj, expected, desired, __ATOMIC_RELEASE, __ATOMIC_RELAXED) +#define atomic_try_cmpxchg_relaxed(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_weak, 4)(obj, expected, desired, __ATOMIC_RELAXED, __ATOMIC_RELAXED) +#define atomic64_cmpxchg(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_strong, 8)(obj, expected, desired, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED) +#define atomic64_cmpxchg_acquire(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_strong, 8)(obj, expected, desired, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED) +#define atomic64_cmpxchg_release(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_strong, 8)(obj, expected, desired, __ATOMIC_RELEASE, __ATOMIC_RELAXED) +#define atomic64_cmpxchg_relaxed(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_strong, 8)(obj, expected, desired, __ATOMIC_RELAXED, __ATOMIC_RELAXED) +#define atomic64_try_cmpxchg(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_weak, 8)(obj, expected, desired, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED) +#define atomic64_try_cmpxchg_acquire(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_weak, 8)(obj, expected, desired, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED) +#define atomic64_try_cmpxchg_release(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_weak, 8)(obj, expected, desired, __ATOMIC_RELEASE, __ATOMIC_RELAXED) +#define atomic64_try_cmpxchg_relaxed(obj, expected, desired) \ + ATOMIC_FUNC(compare_exchange_weak, 8)(obj, expected, desired, __ATOMIC_RELAXED, __ATOMIC_RELAXED) + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -106,6 +194,41 @@ extern "C" #define EXTERN extern #endif +void nx_atomic_store_4(FAR volatile void *ptr, int32_t value, int memorder); +void nx_atomic_store_8(FAR volatile void *ptr, int64_t value, int memorder); +int32_t nx_atomic_load_4(FAR const volatile void *ptr, int memorder); +int64_t nx_atomic_load_8(FAR const volatile void *ptr, int memorder); +int32_t nx_atomic_exchange_4(FAR volatile void *ptr, int32_t value, + int memorder); +int64_t nx_atomic_exchange_8(FAR volatile void *ptr, int64_t value, + int memorder); +bool nx_atomic_compare_exchange_4(FAR volatile void *ptr, FAR void *expect, + int32_t desired, bool weak, + int success, int failure); +bool nx_atomic_compare_exchange_8(FAR volatile void *ptr, FAR void *expect, + int64_t desired, bool weak, + int success, int failure); +int32_t nx_atomic_fetch_add_4(FAR volatile void *ptr, int32_t value, + int memorder); +int64_t nx_atomic_fetch_add_8(FAR volatile void *ptr, int64_t value, + int memorder); +int32_t nx_atomic_fetch_sub_4(FAR volatile void *ptr, int32_t value, + int memorder); +int64_t nx_atomic_fetch_sub_8(FAR volatile void *ptr, int64_t value, + int memorder); +int32_t nx_atomic_fetch_and_4(FAR volatile void *ptr, int32_t value, + int memorder); +int64_t nx_atomic_fetch_and_8(FAR volatile void *ptr, int64_t value, + int memorder); +int32_t nx_atomic_fetch_or_4(FAR volatile void *ptr, int32_t value, + int memorder); +int64_t nx_atomic_fetch_or_8(FAR volatile void *ptr, int64_t value, + int memorder); +int32_t nx_atomic_fetch_xor_4(FAR volatile void *ptr, int32_t value, + int memorder); +int64_t nx_atomic_fetch_xor_8(FAR volatile void *ptr, int64_t value, + int memorder); + #undef EXTERN #if defined(__cplusplus) } diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 1ef5dba359..e82df41bff 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -404,7 +404,7 @@ struct inode FAR struct inode *i_parent; /* Link to parent level inode */ FAR struct inode *i_peer; /* Link to same level inode */ FAR struct inode *i_child; /* Link to lower level inode */ - atomic_short i_crefs; /* References to inode */ + atomic_t i_crefs; /* References to inode */ uint16_t i_flags; /* Flags for inode */ union inode_ops_u u; /* Inode operations */ ino_t i_ino; /* Inode serial number */ diff --git a/include/nuttx/i3c/master.h b/include/nuttx/i3c/master.h index fc78722ea7..cbc40db4a2 100644 --- a/include/nuttx/i3c/master.h +++ b/include/nuttx/i3c/master.h @@ -28,8 +28,8 @@ ****************************************************************************/ #include -#include +#include #include #include #include @@ -231,7 +231,7 @@ struct i3c_ibi_slot struct i3c_device_ibi_info { sem_t all_ibis_handled; - atomic_int pending_ibis; + atomic_t pending_ibis; unsigned int max_payload_len; unsigned int num_slots; unsigned int enabled; diff --git a/include/nuttx/lib/stdatomic.h b/include/nuttx/lib/stdatomic.h deleted file mode 100644 index 48972b61ae..0000000000 --- a/include/nuttx/lib/stdatomic.h +++ /dev/null @@ -1,278 +0,0 @@ -/**************************************************************************** - * include/nuttx/lib/stdatomic.h - * - * 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. - * - ****************************************************************************/ - -#ifndef __INCLUDE_NUTTX_LIB_STDATOMIC_H -#define __INCLUDE_NUTTX_LIB_STDATOMIC_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef __ATOMIC_RELAXED -# define __ATOMIC_RELAXED 0 -#endif - -#ifndef __ATOMIC_CONSUM -# define __ATOMIC_CONSUME 1 -#endif - -#ifndef __ATOMIC_ACQUIR -# define __ATOMIC_ACQUIRE 2 -#endif - -#ifndef __ATOMIC_RELEAS -# define __ATOMIC_RELEASE 3 -#endif - -#ifndef __ATOMIC_ACQ_REL -# define __ATOMIC_ACQ_REL 4 -#endif - -#ifndef __ATOMIC_SEQ_CS -# define __ATOMIC_SEQ_CST 5 -#endif - -#define ATOMIC_FLAG_INIT 0 -#define ATOMIC_VAR_INIT(value) (value) - -#define atomic_store_n(obj, val, type) \ - (sizeof(*(obj)) == 1 ? nx_atomic_store_1(obj, val, type) : \ - sizeof(*(obj)) == 2 ? nx_atomic_store_2(obj, val, type) : \ - sizeof(*(obj)) == 4 ? nx_atomic_store_4(obj, val, type) : \ - nx_atomic_store_8(obj, val, type)) - -#define atomic_store(obj, val) atomic_store_n(obj, val, __ATOMIC_RELAXED) -#define atomic_store_explicit(obj, val, type) atomic_store_n(obj, val, type) -#define atomic_init(obj, val) atomic_store(obj, val) - -#define atomic_load_n(obj, type) \ - (sizeof(*(obj)) == 1 ? nx_atomic_load_1(obj, type) : \ - sizeof(*(obj)) == 2 ? nx_atomic_load_2(obj, type) : \ - sizeof(*(obj)) == 4 ? nx_atomic_load_4(obj, type) : \ - nx_atomic_load_8(obj, type)) - -#define atomic_load(obj) atomic_load_n(obj, __ATOMIC_RELAXED) -#define atomic_load_explicit(obj, type) atomic_load_n(obj, type) - -#define atomic_exchange_n(obj, val, type) \ - (sizeof(*(obj)) == 1 ? nx_atomic_exchange_1(obj, val, type) : \ - sizeof(*(obj)) == 2 ? nx_atomic_exchange_2(obj, val, type) : \ - sizeof(*(obj)) == 4 ? nx_atomic_exchange_4(obj, val, type) : \ - nx_atomic_exchange_8(obj, val, type)) - -#define atomic_exchange(obj, val) atomic_exchange_n(obj, val, __ATOMIC_RELAXED) -#define atomic_exchange_explicit(obj, val, type) atomic_exchange_n(obj, val, type) - -#define atomic_compare_exchange_n(obj, expected, desired, weak, success, failure) \ - (sizeof(*(obj)) == 1 ? nx_atomic_compare_exchange_1(obj, expected, desired, weak, success, failure) : \ - sizeof(*(obj)) == 2 ? nx_atomic_compare_exchange_2(obj, expected, desired, weak, success, failure) : \ - sizeof(*(obj)) == 4 ? nx_atomic_compare_exchange_4(obj, expected, desired, weak, success, failure) : \ - nx_atomic_compare_exchange_8(obj, expected, desired, weak, success, failure)) - -#define atomic_compare_exchange_strong(obj, expected, desired) \ - atomic_compare_exchange_n(obj, expected, desired, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED) -#define atomic_compare_exchange_strong_explicit(obj, expected, desired, success, failure) \ - atomic_compare_exchange_n(obj, expected, desired, false, success, failure) -#define atomic_compare_exchange_weak(obj, expected, desired) \ - atomic_compare_exchange_n(obj, expected, desired, true, __ATOMIC_RELAXED, __ATOMIC_RELAXED) -#define atomic_compare_exchange_weak_explicit(obj, expected, desired, success, failure) \ - atomic_compare_exchange_n(obj, expected, desired, true, success, failure) - -#define atomic_flag_test_and_set_n(obj, type) \ - (sizeof(*(obj)) == 1 ? nx_atomic_flag_test_and_set_1(obj, type) : \ - sizeof(*(obj)) == 2 ? nx_atomic_flag_test_and_set_2(obj, type) : \ - sizeof(*(obj)) == 4 ? nx_atomic_flag_test_and_set_4(obj, type) : \ - nx_atomic_flag_test_and_set_8(obj, type)) - -#define atomic_flag_test_and_set(obj) atomic_flag_test_and_set_n(obj, __ATOMIC_RELAXED) -#define atomic_flag_test_and_set_explicit(obj, type) atomic_flag_test_and_set_n(obj, 1, type) -#define atomic_flag_clear(obj) atomic_store(obj, 0) -#define atomic_flag_clear_explicit(obj, type) atomic_store_explicit(obj, 0, type) - -#define atomic_fetch_and_n(obj, val, type) \ - (sizeof(*(obj)) == 1 ? nx_atomic_fetch_and_1(obj, val, type) : \ - sizeof(*(obj)) == 2 ? nx_atomic_fetch_and_2(obj, val, type) : \ - sizeof(*(obj)) == 4 ? nx_atomic_fetch_and_4(obj, val, type) : \ - nx_atomic_fetch_and_8(obj, val, type)) - -#define atomic_fetch_and(obj, val) atomic_fetch_and_n(obj, val, __ATOMIC_RELAXED) -#define atomic_fetch_and_explicit(obj, val, type) atomic_fetch_and_n(obj, val, type) - -#define atomic_fetch_or_n(obj, val, type) \ - (sizeof(*(obj)) == 1 ? nx_atomic_fetch_or_1(obj, val, type) : \ - sizeof(*(obj)) == 2 ? nx_atomic_fetch_or_2(obj, val, type) : \ - sizeof(*(obj)) == 4 ? nx_atomic_fetch_or_4(obj, val, type) : \ - nx_atomic_fetch_or_8(obj, val, type)) - -#define atomic_fetch_or(obj, val) atomic_fetch_or_n(obj, val, __ATOMIC_RELAXED) -#define atomic_fetch_or_explicit(obj, val, type) atomic_fetch_or_n(obj, val, type) - -#define atomic_fetch_xor_n(obj, val, type) \ - (sizeof(*(obj)) == 1 ? nx_atomic_fetch_xor_1(obj, val, type) : \ - sizeof(*(obj)) == 2 ? nx_atomic_fetch_xor_2(obj, val, type) : \ - sizeof(*(obj)) == 4 ? nx_atomic_fetch_xor_4(obj, val, type) : \ - nx_atomic_fetch_xor_8(obj, val, type)) - -#define atomic_fetch_xor(obj, val) atomic_fetch_xor_n(obj, val, __ATOMIC_RELAXED) -#define atomic_fetch_xor_explicit(obj, val, type) atomic_fetch_xor_n(obj, val, type) - -#define atomic_fetch_add_n(obj, val, type) \ - (sizeof(*(obj)) == 1 ? nx_atomic_fetch_add_1(obj, val, type) : \ - sizeof(*(obj)) == 2 ? nx_atomic_fetch_add_2(obj, val, type) : \ - sizeof(*(obj)) == 4 ? nx_atomic_fetch_add_4(obj, val, type) : \ - nx_atomic_fetch_add_8(obj, val, type)) - -#define atomic_fetch_add(obj, val) atomic_fetch_add_n(obj, val, __ATOMIC_RELAXED) -#define atomic_fetch_add_explicit(obj, val, type) atomic_fetch_add_n(obj, val, type) - -#define atomic_fetch_sub_n(obj, val, type) \ - (sizeof(*(obj)) == 1 ? nx_atomic_fetch_sub_1(obj, val, type) : \ - sizeof(*(obj)) == 2 ? nx_atomic_fetch_sub_2(obj, val, type) : \ - sizeof(*(obj)) == 4 ? nx_atomic_fetch_sub_4(obj, val, type) : \ - nx_atomic_fetch_sub_8(obj, val, type)) - -#define atomic_fetch_sub(obj, val) atomic_fetch_sub_n(obj, val, __ATOMIC_RELAXED) -#define atomic_fetch_sub_explicit(obj, val, type) atomic_fetch_sub_n(obj, val, type) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef enum -{ - memory_order_relaxed = __ATOMIC_RELAXED, - memory_order_consume = __ATOMIC_CONSUME, - memory_order_acquire = __ATOMIC_ACQUIRE, - memory_order_release = __ATOMIC_RELEASE, - memory_order_acq_rel = __ATOMIC_ACQ_REL, - memory_order_seq_cst = __ATOMIC_SEQ_CST -} memory_order; - -typedef volatile int atomic_flag; -typedef volatile bool atomic_bool; -typedef volatile char atomic_char; -typedef volatile signed char atomic_schar; -typedef volatile unsigned char atomic_uchar; -typedef volatile short atomic_short; -typedef volatile unsigned short atomic_ushort; -typedef volatile int atomic_int; -typedef volatile unsigned int atomic_uint; -typedef volatile long atomic_long; -typedef volatile unsigned long atomic_ulong; -typedef volatile long long atomic_llong; -typedef volatile unsigned long long atomic_ullong; -typedef volatile wchar_t atomic_wchar_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void nx_atomic_store_1(FAR volatile void *ptr, uint8_t value, - int memorder); -void nx_atomic_store_2(FAR volatile void *ptr, uint16_t value, - int memorder); -void nx_atomic_store_4(FAR volatile void *ptr, uint32_t value, - int memorder); -void nx_atomic_store_8(FAR volatile void *ptr, uint64_t value, - int memorder); -uint8_t nx_atomic_load_1(FAR const volatile void *ptr, int memorder); -uint16_t nx_atomic_load_2(FAR const volatile void *ptr, int memorder); -uint32_t nx_atomic_load_4(FAR const volatile void *ptr, int memorder); -uint64_t nx_atomic_load_8(FAR const volatile void *ptr, int memorder); -uint8_t nx_atomic_exchange_1(FAR volatile void *ptr, uint8_t value, - int memorder); -uint16_t nx_atomic_exchange_2(FAR volatile void *ptr, uint16_t value, - int memorder); -uint32_t nx_atomic_exchange_4(FAR volatile void *ptr, uint32_t value, - int memorder); -uint64_t nx_atomic_exchange_8(FAR volatile void *ptr, uint64_t value, - int memorder); -bool nx_atomic_compare_exchange_1(FAR volatile void *mem, FAR void *expect, - uint8_t desired, bool weak, int success, - int failure); -bool nx_atomic_compare_exchange_2(FAR volatile void *mem, FAR void *expect, - uint16_t desired, bool weak, int success, - int failure); -bool nx_atomic_compare_exchange_4(FAR volatile void *mem, FAR void *expect, - uint32_t desired, bool weak, int success, - int failure); -bool nx_atomic_compare_exchange_8(FAR volatile void *mem, FAR void *expect, - uint64_t desired, bool weak, int success, - int failure); -uint8_t nx_atomic_flag_test_and_set_1(FAR const volatile void *ptr, - int memorder); -uint16_t nx_atomic_flag_test_and_set_2(FAR const volatile void *ptr, - int memorder); -uint32_t nx_atomic_flag_test_and_set_4(FAR const volatile void *ptr, - int memorder); -uint64_t nx_atomic_flag_test_and_set_8(FAR const volatile void *ptr, - int memorder); -uint8_t nx_atomic_fetch_add_1(FAR volatile void *ptr, uint8_t value, - int memorder); -uint16_t nx_atomic_fetch_add_2(FAR volatile void *ptr, uint16_t value, - int memorder); -uint32_t nx_atomic_fetch_add_4(FAR volatile void *ptr, uint32_t value, - int memorder); -uint64_t nx_atomic_fetch_add_8(FAR volatile void *ptr, uint64_t value, - int memorder); -uint8_t nx_atomic_fetch_sub_1(FAR volatile void *ptr, uint8_t value, - int memorder); -uint16_t nx_atomic_fetch_sub_2(FAR volatile void *ptr, uint16_t value, - int memorder); -uint32_t nx_atomic_fetch_sub_4(FAR volatile void *ptr, uint32_t value, - int memorder); -uint64_t nx_atomic_fetch_sub_8(FAR volatile void *ptr, uint64_t value, - int memorder); -uint8_t nx_atomic_fetch_and_1(FAR volatile void *ptr, uint8_t value, - int memorder); -uint16_t nx_atomic_fetch_and_2(FAR volatile void *ptr, uint16_t value, - int memorder); -uint32_t nx_atomic_fetch_and_4(FAR volatile void *ptr, uint32_t value, - int memorder); -uint64_t nx_atomic_fetch_and_8(FAR volatile void *ptr, uint64_t value, - int memorder); -uint8_t nx_atomic_fetch_or_1(FAR volatile void *ptr, uint8_t value, - int memorder); -uint16_t nx_atomic_fetch_or_2(FAR volatile void *ptr, uint16_t value, - int memorder); -uint32_t nx_atomic_fetch_or_4(FAR volatile void *ptr, uint32_t value, - int memorder); -uint64_t nx_atomic_fetch_or_8(FAR volatile void *ptr, uint64_t value, - int memorder); -uint8_t nx_atomic_fetch_xor_1(FAR volatile void *ptr, uint8_t value, - int memorder); -uint16_t nx_atomic_fetch_xor_2(FAR volatile void *ptr, uint16_t value, - int memorder); -uint32_t nx_atomic_fetch_xor_4(FAR volatile void *ptr, uint32_t value, - int memorder); -uint64_t nx_atomic_fetch_xor_8(FAR volatile void *ptr, uint64_t value, - int memorder); - -#endif /* __INCLUDE_NUTTX_LIB_STDATOMIC_H */ diff --git a/include/nuttx/net/netdev_lowerhalf.h b/include/nuttx/net/netdev_lowerhalf.h index bf56e0f267..ee61e49108 100644 --- a/include/nuttx/net/netdev_lowerhalf.h +++ b/include/nuttx/net/netdev_lowerhalf.h @@ -117,7 +117,7 @@ struct netdev_lowerhalf_s /* Max # of buffer held by driver */ - atomic_int quota[NETPKT_TYPENUM]; + atomic_t quota[NETPKT_TYPENUM]; /* The structure used by net stack. * Note: Do not change its fields unless you know what you are doing. diff --git a/include/nuttx/reset/reset.h b/include/nuttx/reset/reset.h index 9d5d908b79..da98d0795f 100644 --- a/include/nuttx/reset/reset.h +++ b/include/nuttx/reset/reset.h @@ -60,12 +60,12 @@ struct reset_control FAR struct reset_controller_dev *rcdev; struct list_node list; unsigned int id; - atomic_int refcnt; + atomic_t refcnt; bool acquired; bool shared; bool array; - atomic_int deassert_count; - atomic_int triggered_count; + atomic_t deassert_count; + atomic_t triggered_count; }; /**************************************************************************** diff --git a/include/nuttx/serial/uart_ram.h b/include/nuttx/serial/uart_ram.h index 04cff1b1f0..f9cd25c46a 100644 --- a/include/nuttx/serial/uart_ram.h +++ b/include/nuttx/serial/uart_ram.h @@ -45,8 +45,8 @@ struct uart_rambuf_s { char buffer[CONFIG_RAM_UART_BUFSIZE]; - atomic_uint wroff; - atomic_uint rdoff; + atomic_t wroff; + atomic_t rdoff; }; /**************************************************************************** diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index 59ff61dc8a..cacf6aa809 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -201,9 +201,8 @@ static inline spinlock_t up_testset(FAR volatile spinlock_t *lock) static inline_function void spin_lock_wo_note(FAR volatile spinlock_t *lock) { #ifdef CONFIG_TICKET_SPINLOCK - unsigned short ticket = - atomic_fetch_add((FAR atomic_ushort *)&lock->tickets.next, 1); - while (atomic_load((FAR atomic_ushort *)&lock->tickets.owner) != ticket) + int ticket = atomic_fetch_add(&lock->next, 1); + while (atomic_read(&lock->owner) != ticket) #else /* CONFIG_TICKET_SPINLOCK */ while (up_testset(lock) == SP_LOCKED) #endif @@ -283,25 +282,8 @@ static inline_function bool spin_trylock_wo_note(FAR volatile spinlock_t *lock) { #ifdef CONFIG_TICKET_SPINLOCK - unsigned short ticket = - atomic_load((FAR atomic_ushort *)&lock->tickets.next); - - spinlock_t oldval = - { - { - ticket, ticket - } - }; - - spinlock_t newval = - { - { - ticket, ticket + 1 - } - }; - - if (!atomic_compare_exchange_strong((FAR atomic_uint *)&lock->value, - &oldval.value, newval.value)) + if (!atomic_cmpxchg(&lock->next, &lock->owner, + atomic_read(&lock->next) + 1)) #else /* CONFIG_TICKET_SPINLOCK */ if (up_testset(lock) == SP_LOCKED) #endif /* CONFIG_TICKET_SPINLOCK */ @@ -389,7 +371,7 @@ spin_unlock_wo_note(FAR volatile spinlock_t *lock) { SP_DMB(); #ifdef CONFIG_TICKET_SPINLOCK - atomic_fetch_add((FAR atomic_ushort *)&lock->tickets.owner, 1); + atomic_fetch_add(&lock->owner, 1); #else *lock = SP_UNLOCKED; #endif @@ -448,7 +430,8 @@ static inline_function void spin_unlock(FAR volatile spinlock_t *lock) /* bool spin_islocked(FAR spinlock_t lock); */ #ifdef CONFIG_TICKET_SPINLOCK -# define spin_is_locked(l) ((*l).tickets.owner != (*l).tickets.next) +# define spin_is_locked(l) \ + (atomic_read(&(*l).owner) != atomic_read(&(*l).next)) #else # define spin_is_locked(l) (*(l) == SP_LOCKED) #endif @@ -751,15 +734,14 @@ static inline_function void read_lock(FAR volatile rwlock_t *lock) { while (true) { - int old = atomic_load((FAR atomic_int *)lock); + int old = atomic_read(lock); if (old <= RW_SP_WRITE_LOCKED) { DEBUGASSERT(old == RW_SP_WRITE_LOCKED); SP_DSB(); SP_WFE(); } - else if(atomic_compare_exchange_strong((FAR atomic_int *)lock, - &old, old + 1)) + else if(atomic_cmpxchg(lock, &old, old + 1)) { break; } @@ -796,14 +778,13 @@ static inline_function bool read_trylock(FAR volatile rwlock_t *lock) { while (true) { - int old = atomic_load((FAR atomic_int *)lock); + int old = atomic_read(lock); if (old <= RW_SP_WRITE_LOCKED) { DEBUGASSERT(old == RW_SP_WRITE_LOCKED); return false; } - else if (atomic_compare_exchange_strong((FAR atomic_int *)lock, - &old, old + 1)) + else if (atomic_cmpxchg(lock, &old, old + 1)) { break; } @@ -832,10 +813,10 @@ static inline_function bool read_trylock(FAR volatile rwlock_t *lock) static inline_function void read_unlock(FAR volatile rwlock_t *lock) { - DEBUGASSERT(atomic_load((FAR atomic_int *)lock) >= RW_SP_READ_LOCKED); + DEBUGASSERT(atomic_read(lock) >= RW_SP_READ_LOCKED); SP_DMB(); - atomic_fetch_sub((FAR atomic_int *)lock, 1); + atomic_fetch_sub(lock, 1); SP_DSB(); SP_SEV(); } @@ -869,8 +850,7 @@ static inline_function void write_lock(FAR volatile rwlock_t *lock) { int zero = RW_SP_UNLOCKED; - while (!atomic_compare_exchange_strong((FAR atomic_int *)lock, - &zero, RW_SP_WRITE_LOCKED)) + while (!atomic_cmpxchg(lock, &zero, RW_SP_WRITE_LOCKED)) { SP_DSB(); SP_WFE(); @@ -908,8 +888,7 @@ static inline_function bool write_trylock(FAR volatile rwlock_t *lock) { int zero = RW_SP_UNLOCKED; - if (atomic_compare_exchange_strong((FAR atomic_int *)lock, - &zero, RW_SP_WRITE_LOCKED)) + if (atomic_cmpxchg(lock, &zero, RW_SP_WRITE_LOCKED)) { SP_DMB(); return true; @@ -940,10 +919,10 @@ static inline_function void write_unlock(FAR volatile rwlock_t *lock) { /* Ensure this cpu already get write lock */ - DEBUGASSERT(atomic_load((FAR atomic_int *)lock) == RW_SP_WRITE_LOCKED); + DEBUGASSERT(atomic_read(lock) == RW_SP_WRITE_LOCKED); SP_DMB(); - atomic_store((FAR atomic_int *)lock, RW_SP_UNLOCKED); + atomic_set(lock, RW_SP_UNLOCKED); SP_DSB(); SP_SEV(); } diff --git a/include/nuttx/spinlock_type.h b/include/nuttx/spinlock_type.h index 939cc96791..db3b64f00e 100644 --- a/include/nuttx/spinlock_type.h +++ b/include/nuttx/spinlock_type.h @@ -39,7 +39,7 @@ extern "C" #endif #if defined(CONFIG_RW_SPINLOCK) -typedef int rwlock_t; +typedef atomic_t rwlock_t; # define RW_SP_UNLOCKED 0 # define RW_SP_READ_LOCKED 1 # define RW_SP_WRITE_LOCKED -1 @@ -52,19 +52,14 @@ typedef int rwlock_t; typedef uint8_t spinlock_t; #elif defined(CONFIG_TICKET_SPINLOCK) -union spinlock_u +typedef struct spinlock_s { - struct - { - unsigned short owner; - unsigned short next; - } tickets; - unsigned int value; -}; -typedef union spinlock_u spinlock_t; + atomic_t owner; + atomic_t next; +} spinlock_t; -# define SP_UNLOCKED (union spinlock_u){{0, 0}} -# define SP_LOCKED (union spinlock_u){{0, 1}} +# define SP_UNLOCKED (spinlock_t){0, 0} +# define SP_LOCKED (spinlock_t){0, 1} #else diff --git a/libs/libc/machine/arch_atomic.c b/libs/libc/machine/arch_atomic.c index 5c22cdc0bc..f0bc841034 100644 --- a/libs/libc/machine/arch_atomic.c +++ b/libs/libc/machine/arch_atomic.c @@ -329,280 +329,260 @@ static spinlock_t g_atomic_lock = SP_UNLOCKED; ****************************************************************************/ STORE(__atomic_store_, 1, uint8_t) -STORE(nx_atomic_store_, 1, uint8_t) /**************************************************************************** * Name: __atomic_store_2 ****************************************************************************/ STORE(__atomic_store_, 2, uint16_t) -STORE(nx_atomic_store_, 2, uint16_t) /**************************************************************************** * Name: __atomic_store_4 ****************************************************************************/ STORE(__atomic_store_, 4, uint32_t) -STORE(nx_atomic_store_, 4, uint32_t) +STORE(nx_atomic_store_, 4, int32_t) /**************************************************************************** * Name: __atomic_store_8 ****************************************************************************/ STORE(__atomic_store_, 8, uint64_t) -STORE(nx_atomic_store_, 8, uint64_t) +STORE(nx_atomic_store_, 8, int64_t) /**************************************************************************** * Name: __atomic_load_1 ****************************************************************************/ LOAD(__atomic_load_, 1, uint8_t) -LOAD(nx_atomic_load_, 1, uint8_t) /**************************************************************************** * Name: __atomic_load__2 ****************************************************************************/ LOAD(__atomic_load_, 2, uint16_t) -LOAD(nx_atomic_load_, 2, uint16_t) /**************************************************************************** * Name: __atomic_load__4 ****************************************************************************/ LOAD(__atomic_load_, 4, uint32_t) -LOAD(nx_atomic_load_, 4, uint32_t) +LOAD(nx_atomic_load_, 4, int32_t) /**************************************************************************** * Name: __atomic_load__8 ****************************************************************************/ LOAD(__atomic_load_, 8, uint64_t) -LOAD(nx_atomic_load_, 8, uint64_t) +LOAD(nx_atomic_load_, 8, int64_t) /**************************************************************************** * Name: __atomic_exchange_1 ****************************************************************************/ EXCHANGE(__atomic_exchange_, 1, uint8_t) -EXCHANGE(nx_atomic_exchange_, 1, uint8_t) /**************************************************************************** * Name: __atomic_exchange__2 ****************************************************************************/ EXCHANGE(__atomic_exchange_, 2, uint16_t) -EXCHANGE(nx_atomic_exchange_, 2, uint16_t) /**************************************************************************** * Name: __atomic_exchange__4 ****************************************************************************/ EXCHANGE(__atomic_exchange_, 4, uint32_t) -EXCHANGE(nx_atomic_exchange_, 4, uint32_t) +EXCHANGE(nx_atomic_exchange_, 4, int32_t) /**************************************************************************** * Name: __atomic_exchange__8 ****************************************************************************/ EXCHANGE(__atomic_exchange_, 8, uint64_t) -EXCHANGE(nx_atomic_exchange_, 8, uint64_t) +EXCHANGE(nx_atomic_exchange_, 8, int64_t) /**************************************************************************** * Name: __atomic_compare_exchange_1 ****************************************************************************/ CMP_EXCHANGE(__atomic_compare_exchange_, 1, uint8_t) -CMP_EXCHANGE(nx_atomic_compare_exchange_, 1, uint8_t) /**************************************************************************** * Name: __atomic_compare_exchange_2 ****************************************************************************/ CMP_EXCHANGE(__atomic_compare_exchange_, 2, uint16_t) -CMP_EXCHANGE(nx_atomic_compare_exchange_, 2, uint16_t) /**************************************************************************** * Name: __atomic_compare_exchange_4 ****************************************************************************/ CMP_EXCHANGE(__atomic_compare_exchange_, 4, uint32_t) -CMP_EXCHANGE(nx_atomic_compare_exchange_, 4, uint32_t) +CMP_EXCHANGE(nx_atomic_compare_exchange_, 4, int32_t) /**************************************************************************** * Name: __atomic_compare_exchange_8 ****************************************************************************/ CMP_EXCHANGE(__atomic_compare_exchange_, 8, uint64_t) -CMP_EXCHANGE(nx_atomic_compare_exchange_, 8, uint64_t) +CMP_EXCHANGE(nx_atomic_compare_exchange_, 8, int64_t) /**************************************************************************** * Name: __atomic_flag_test_and_set_1 ****************************************************************************/ FLAG_TEST_AND_SET(__atomic_flags_test_and_set_, 1, uint8_t) -FLAG_TEST_AND_SET(nx_atomic_flags_test_and_set_, 1, uint8_t) /**************************************************************************** * Name: __atomic_flag_test_and_set_2 ****************************************************************************/ FLAG_TEST_AND_SET(__atomic_flags_test_and_set_, 2, uint16_t) -FLAG_TEST_AND_SET(nx_atomic_flags_test_and_set_, 2, uint16_t) /**************************************************************************** * Name: __atomic_flag_test_and_set_4 ****************************************************************************/ FLAG_TEST_AND_SET(__atomic_flags_test_and_set_, 4, uint32_t) -FLAG_TEST_AND_SET(nx_atomic_flags_test_and_set_, 4, uint32_t) +FLAG_TEST_AND_SET(nx_atomic_flags_test_and_set_, 4, int32_t) /**************************************************************************** * Name: __atomic_flag_test_and_set_8 ****************************************************************************/ FLAG_TEST_AND_SET(__atomic_flags_test_and_set_, 8, uint64_t) -FLAG_TEST_AND_SET(nx_atomic_flags_test_and_set_, 8, uint64_t) +FLAG_TEST_AND_SET(nx_atomic_flags_test_and_set_, 8, int64_t) /**************************************************************************** * Name: __atomic_fetch_add_1 ****************************************************************************/ FETCH_ADD(__atomic_fetch_add_, 1, uint8_t) -FETCH_ADD(nx_atomic_fetch_add_, 1, uint8_t) /**************************************************************************** * Name: __atomic_fetch_add_2 ****************************************************************************/ FETCH_ADD(__atomic_fetch_add_, 2, uint16_t) -FETCH_ADD(nx_atomic_fetch_add_, 2, uint16_t) /**************************************************************************** * Name: __atomic_fetch_add_4 ****************************************************************************/ FETCH_ADD(__atomic_fetch_add_, 4, uint32_t) -FETCH_ADD(nx_atomic_fetch_add_, 4, uint32_t) +FETCH_ADD(nx_atomic_fetch_add_, 4, int32_t) /**************************************************************************** * Name: __atomic_fetch_add_8 ****************************************************************************/ FETCH_ADD(__atomic_fetch_add_, 8, uint64_t) -FETCH_ADD(nx_atomic_fetch_add_, 8, uint64_t) +FETCH_ADD(nx_atomic_fetch_add_, 8, int64_t) /**************************************************************************** * Name: __atomic_fetch_sub_1 ****************************************************************************/ FETCH_SUB(__atomic_fetch_sub_, 1, uint8_t) -FETCH_SUB(nx_atomic_fetch_sub_, 1, uint8_t) /**************************************************************************** * Name: __atomic_fetch_sub_2 ****************************************************************************/ FETCH_SUB(__atomic_fetch_sub_, 2, uint16_t) -FETCH_SUB(nx_atomic_fetch_sub_, 2, uint16_t) /**************************************************************************** * Name: __atomic_fetch_sub_4 ****************************************************************************/ FETCH_SUB(__atomic_fetch_sub_, 4, uint32_t) -FETCH_SUB(nx_atomic_fetch_sub_, 4, uint32_t) +FETCH_SUB(nx_atomic_fetch_sub_, 4, int32_t) /**************************************************************************** * Name: __atomic_fetch_sub_8 ****************************************************************************/ FETCH_SUB(__atomic_fetch_sub_, 8, uint64_t) -FETCH_SUB(nx_atomic_fetch_sub_, 8, uint64_t) +FETCH_SUB(nx_atomic_fetch_sub_, 8, int64_t) /**************************************************************************** * Name: __atomic_fetch_and_1 ****************************************************************************/ FETCH_AND(__atomic_fetch_and_, 1, uint8_t) -FETCH_AND(nx_atomic_fetch_and_, 1, uint8_t) /**************************************************************************** * Name: __atomic_fetch_and_2 ****************************************************************************/ FETCH_AND(__atomic_fetch_and_, 2, uint16_t) -FETCH_AND(nx_atomic_fetch_and_, 2, uint16_t) /**************************************************************************** * Name: __atomic_fetch_and_4 ****************************************************************************/ FETCH_AND(__atomic_fetch_and_, 4, uint32_t) -FETCH_AND(nx_atomic_fetch_and_, 4, uint32_t) +FETCH_AND(nx_atomic_fetch_and_, 4, int32_t) /**************************************************************************** * Name: __atomic_fetch_and_8 ****************************************************************************/ FETCH_AND(__atomic_fetch_and_, 8, uint64_t) -FETCH_AND(nx_atomic_fetch_and_, 8, uint64_t) +FETCH_AND(nx_atomic_fetch_and_, 8, int64_t) /**************************************************************************** * Name: __atomic_fetch_or_1 ****************************************************************************/ FETCH_OR(__atomic_fetch_or_, 1, uint8_t) -FETCH_OR(nx_atomic_fetch_or_, 1, uint8_t) /**************************************************************************** * Name: __atomic_fetch_or_2 ****************************************************************************/ FETCH_OR(__atomic_fetch_or_, 2, uint16_t) -FETCH_OR(nx_atomic_fetch_or_, 2, uint16_t) /**************************************************************************** * Name: __atomic_fetch_or_4 ****************************************************************************/ FETCH_OR(__atomic_fetch_or_, 4, uint32_t) -FETCH_OR(nx_atomic_fetch_or_, 4, uint32_t) +FETCH_OR(nx_atomic_fetch_or_, 4, int32_t) /**************************************************************************** * Name: __atomic_fetch_or_4 ****************************************************************************/ FETCH_OR(__atomic_fetch_or_, 8, uint64_t) -FETCH_OR(nx_atomic_fetch_or_, 8, uint64_t) +FETCH_OR(nx_atomic_fetch_or_, 8, int64_t) /**************************************************************************** * Name: __atomic_fetch_xor_1 ****************************************************************************/ FETCH_XOR(__atomic_fetch_xor_, 1, uint8_t) -FETCH_XOR(nx_atomic_fetch_xor_, 1, uint8_t) /**************************************************************************** * Name: __atomic_fetch_xor_2 ****************************************************************************/ FETCH_XOR(__atomic_fetch_xor_, 2, uint16_t) -FETCH_XOR(nx_atomic_fetch_xor_, 2, uint16_t) /**************************************************************************** * Name: __atomic_fetch_xor_4 ****************************************************************************/ FETCH_XOR(__atomic_fetch_xor_, 4, uint32_t) -FETCH_XOR(nx_atomic_fetch_xor_, 4, uint32_t) +FETCH_XOR(nx_atomic_fetch_xor_, 4, int32_t) /**************************************************************************** * Name: __atomic_fetch_xor_8 ****************************************************************************/ FETCH_XOR(__atomic_fetch_xor_, 8, uint64_t) -FETCH_XOR(nx_atomic_fetch_xor_, 8, uint64_t) +FETCH_XOR(nx_atomic_fetch_xor_, 8, int64_t) /* Clang define the __sync builtins, add #ifndef to avoid * redefined/redeclared problem. @@ -615,224 +595,192 @@ FETCH_XOR(nx_atomic_fetch_xor_, 8, uint64_t) ****************************************************************************/ SYNC_ADD_FETCH(__sync_add_and_fetch_, 1, uint8_t) -SYNC_ADD_FETCH(nx_sync_add_and_fetch_, 1, uint8_t) /**************************************************************************** * Name: __sync_add_and_fetch_2 ****************************************************************************/ SYNC_ADD_FETCH(__sync_add_and_fetch_, 2, uint16_t) -SYNC_ADD_FETCH(nx_sync_add_and_fetch_, 2, uint16_t) /**************************************************************************** * Name: __sync_add_and_fetch_4 ****************************************************************************/ SYNC_ADD_FETCH(__sync_add_and_fetch_, 4, uint32_t) -SYNC_ADD_FETCH(nx_sync_add_and_fetch_, 4, uint32_t) /**************************************************************************** * Name: __sync_add_and_fetch_8 ****************************************************************************/ SYNC_ADD_FETCH(__sync_add_and_fetch_, 8, uint64_t) -SYNC_ADD_FETCH(nx_sync_add_and_fetch_, 8, uint64_t) /**************************************************************************** * Name: __sync_sub_and_fetch_1 ****************************************************************************/ SYNC_SUB_FETCH(__sync_sub_and_fetch_, 1, uint8_t) -SYNC_SUB_FETCH(nx_sync_sub_and_fetch_, 1, uint8_t) /**************************************************************************** * Name: __sync_sub_and_fetch_2 ****************************************************************************/ SYNC_SUB_FETCH(__sync_sub_and_fetch_, 2, uint16_t) -SYNC_SUB_FETCH(nx_sync_sub_and_fetch_, 2, uint16_t) /**************************************************************************** * Name: __sync_sub_and_fetch_4 ****************************************************************************/ SYNC_SUB_FETCH(__sync_sub_and_fetch_, 4, uint32_t) -SYNC_SUB_FETCH(nx_sync_sub_and_fetch_, 4, uint32_t) /**************************************************************************** * Name: __sync_sub_and_fetch_8 ****************************************************************************/ SYNC_SUB_FETCH(__sync_sub_and_fetch_, 8, uint64_t) -SYNC_SUB_FETCH(nx_sync_sub_and_fetch_, 8, uint64_t) /**************************************************************************** * Name: __sync_or_and_fetch_1 ****************************************************************************/ SYNC_OR_FETCH(__sync_or_and_fetch_, 1, uint8_t) -SYNC_OR_FETCH(nx_sync_or_and_fetch_, 1, uint8_t) /**************************************************************************** * Name: __sync_or_and_fetch_2 ****************************************************************************/ SYNC_OR_FETCH(__sync_or_and_fetch_, 2, uint16_t) -SYNC_OR_FETCH(nx_sync_or_and_fetch_, 2, uint16_t) /**************************************************************************** * Name: __sync_or_and_fetch_4 ****************************************************************************/ SYNC_OR_FETCH(__sync_or_and_fetch_, 4, uint32_t) -SYNC_OR_FETCH(nx_sync_or_and_fetch_, 4, uint32_t) /**************************************************************************** * Name: __sync_or_and_fetch_8 ****************************************************************************/ SYNC_OR_FETCH(__sync_or_and_fetch_, 8, uint64_t) -SYNC_OR_FETCH(nx_sync_or_and_fetch_, 8, uint64_t) /**************************************************************************** * Name: __sync_and_and_fetch_1 ****************************************************************************/ SYNC_AND_FETCH(__sync_and_and_fetch_, 1, uint8_t) -SYNC_AND_FETCH(nx_sync_and_and_fetch_, 1, uint8_t) /**************************************************************************** * Name: __sync_and_and_fetch_2 ****************************************************************************/ SYNC_AND_FETCH(__sync_and_and_fetch_, 2, uint16_t) -SYNC_AND_FETCH(nx_sync_and_and_fetch_, 2, uint16_t) /**************************************************************************** * Name: __sync_and_and_fetch_4 ****************************************************************************/ SYNC_AND_FETCH(__sync_and_and_fetch_, 4, uint32_t) -SYNC_AND_FETCH(nx_sync_and_and_fetch_, 4, uint32_t) /**************************************************************************** * Name: __sync_and_and_fetch_8 ****************************************************************************/ SYNC_AND_FETCH(__sync_and_and_fetch_, 8, uint64_t) -SYNC_AND_FETCH(nx_sync_and_and_fetch_, 8, uint64_t) /**************************************************************************** * Name: __sync_xor_and_fetch_1 ****************************************************************************/ SYNC_XOR_FETCH(__sync_xor_and_fetch_, 1, uint8_t) -SYNC_XOR_FETCH(nx_sync_xor_and_fetch_, 1, uint8_t) /**************************************************************************** * Name: __sync_xor_and_fetch_2 ****************************************************************************/ SYNC_XOR_FETCH(__sync_xor_and_fetch_, 2, uint16_t) -SYNC_XOR_FETCH(nx_sync_xor_and_fetch_, 2, uint16_t) /**************************************************************************** * Name: __sync_xor_and_fetch_4 ****************************************************************************/ SYNC_XOR_FETCH(__sync_xor_and_fetch_, 4, uint32_t) -SYNC_XOR_FETCH(nx_sync_xor_and_fetch_, 4, uint32_t) /**************************************************************************** * Name: __sync_xor_and_fetch_8 ****************************************************************************/ SYNC_XOR_FETCH(__sync_xor_and_fetch_, 8, uint64_t) -SYNC_XOR_FETCH(nx_sync_xor_and_fetch_, 8, uint64_t) /**************************************************************************** * Name: __sync_nand_and_fetch_1 ****************************************************************************/ SYNC_NAND_FETCH(__sync_nand_and_fetch_, 1, uint8_t) -SYNC_NAND_FETCH(nx_sync_nand_and_fetch_, 1, uint8_t) /**************************************************************************** * Name: __sync_nand_and_fetch_2 ****************************************************************************/ SYNC_NAND_FETCH(__sync_nand_and_fetch_, 2, uint16_t) -SYNC_NAND_FETCH(nx_sync_nand_and_fetch_, 2, uint16_t) /**************************************************************************** * Name: __sync_nand_and_fetch_4 ****************************************************************************/ SYNC_NAND_FETCH(__sync_nand_and_fetch_, 4, uint32_t) -SYNC_NAND_FETCH(nx_sync_nand_and_fetch_, 4, uint32_t) /**************************************************************************** * Name: __sync_nand_and_fetch_8 ****************************************************************************/ SYNC_NAND_FETCH(__sync_nand_and_fetch_, 8, uint64_t) -SYNC_NAND_FETCH(nx_sync_nand_and_fetch_, 8, uint64_t) /**************************************************************************** * Name: __sync_bool_compare_and_swap_1 ****************************************************************************/ SYNC_BOOL_CMP_SWAP(__sync_bool_compare_and_swap_, 1, uint8_t) -SYNC_BOOL_CMP_SWAP(nx_sync_bool_compare_and_swap_, 1, uint8_t) /**************************************************************************** * Name: __sync_bool_compare_and_swap_2 ****************************************************************************/ SYNC_BOOL_CMP_SWAP(__sync_bool_compare_and_swap_, 2, uint16_t) -SYNC_BOOL_CMP_SWAP(nx_sync_bool_compare_and_swap_, 2, uint16_t) /**************************************************************************** * Name: __sync_bool_compare_and_swap_4 ****************************************************************************/ SYNC_BOOL_CMP_SWAP(__sync_bool_compare_and_swap_, 4, uint32_t) -SYNC_BOOL_CMP_SWAP(nx_sync_bool_compare_and_swap_, 4, uint32_t) /**************************************************************************** * Name: __sync_bool_compare_and_swap_8 ****************************************************************************/ SYNC_BOOL_CMP_SWAP(__sync_bool_compare_and_swap_, 8, uint64_t) -SYNC_BOOL_CMP_SWAP(nx_sync_bool_compare_and_swap_, 8, uint64_t) /**************************************************************************** * Name: __sync_val_compare_and_swap_1 ****************************************************************************/ SYNC_VAL_CMP_SWAP(__sync_val_compare_and_swap_, 1, uint8_t) -SYNC_VAL_CMP_SWAP(nx_sync_val_compare_and_swap_, 1, uint8_t) /**************************************************************************** * Name: __sync_val_compare_and_swap_2 ****************************************************************************/ SYNC_VAL_CMP_SWAP(__sync_val_compare_and_swap_, 2, uint16_t) -SYNC_VAL_CMP_SWAP(nx_sync_val_compare_and_swap_, 2, uint16_t) /**************************************************************************** * Name: __sync_val_compare_and_swap_4 ****************************************************************************/ SYNC_VAL_CMP_SWAP(__sync_val_compare_and_swap_, 4, uint32_t) -SYNC_VAL_CMP_SWAP(nx_sync_val_compare_and_swap_, 4, uint32_t) /**************************************************************************** * Name: __sync_val_compare_and_swap_8 ****************************************************************************/ SYNC_VAL_CMP_SWAP(__sync_val_compare_and_swap_, 8, uint64_t) -SYNC_VAL_CMP_SWAP(nx_sync_val_compare_and_swap_, 8, uint64_t) /**************************************************************************** * Name: __sync_synchronize diff --git a/libs/libc/misc/lib_fdsan.c b/libs/libc/misc/lib_fdsan.c index f85dd59b34..0d349b7c76 100644 --- a/libs/libc/misc/lib_fdsan.c +++ b/libs/libc/misc/lib_fdsan.c @@ -199,7 +199,7 @@ void android_fdsan_exchange_owner_tag(int fd, uint64_t expected_tag, * but expected == actual? ******************************************************************/ - ferr("fdsan atomic_compare_exchange_strong failed unexpectedly " + ferr("fdsan atomic_cmpxchg failed unexpectedly " "while exchanging owner tag\n"); PANIC(); } diff --git a/wireless/bluetooth/bt_atomic.h b/wireless/bluetooth/bt_atomic.h index ea87754d54..6666bab7c7 100644 --- a/wireless/bluetooth/bt_atomic.h +++ b/wireless/bluetooth/bt_atomic.h @@ -37,9 +37,9 @@ * Pre-processor Definitions ****************************************************************************/ -#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_set(ptr, value) atomic_set(ptr, value); +#define bt_atomic_get(ptr) atomic_read(ptr) +#define bt_atomic_testbit(ptr, bitno) ((atomic_read(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))) @@ -51,6 +51,6 @@ * Public Types ****************************************************************************/ -typedef atomic_char bt_atomic_t; +typedef atomic_t bt_atomic_t; #endif /* __WIRELESS_BLUETOOTH_BT_ATOMIC_H */