diff --git a/arch/arm/src/cxd56xx/cxd56_sph.c b/arch/arm/src/cxd56xx/cxd56_sph.c index 72e6b0cbb257c..b5d58bc22fca2 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_long_load(&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 c0eeb97125331..7f778b82a65af 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_long_load(&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_long_load(&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 7b95441f7a115..821174f107d11 100644 --- a/arch/sim/src/sim/sim_heap.c +++ b/arch/sim/src/sim/sim_heap.c @@ -58,9 +58,9 @@ struct mm_heap_s size_t mm_delaycount[CONFIG_SMP_NCPUS]; #endif - atomic_int aordblks; - atomic_int uordblks; - atomic_int usmblks; + atomic_long_t aordblks; + atomic_long_t uordblks; + atomic_long_t usmblks; #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) struct procfs_meminfo_entry_s mm_procfs; @@ -184,8 +184,8 @@ static void mm_delayfree(struct mm_heap_s *heap, void *mem, bool delay) else { int size = host_mallocsize(mem); - atomic_fetch_sub(&heap->aordblks, 1); - atomic_fetch_sub(&heap->uordblks, size); + atomic_long_fetch_sub(&heap->aordblks, 1); + atomic_long_fetch_sub(&heap->uordblks, size); sched_note_heap(NOTE_HEAP_FREE, heap, mem, size, 0); host_free(mem); } @@ -379,13 +379,13 @@ void *mm_realloc(struct mm_heap_s *heap, void *oldmem, } oldsize = host_mallocsize(oldmem); - atomic_fetch_sub(&heap->uordblks, oldsize); + atomic_long_fetch_sub(&heap->uordblks, oldsize); mem = host_realloc(oldmem, size); - atomic_fetch_add(&heap->aordblks, oldmem == NULL && mem != NULL); + atomic_long_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); + atomic_long_fetch_add(&heap->uordblks, newsize); + usmblks = atomic_long_load(&heap->usmblks); if (mem != NULL) { if (oldmem != NULL) @@ -398,13 +398,14 @@ void *mm_realloc(struct mm_heap_s *heap, void *oldmem, do { - uordblks = atomic_load(&heap->uordblks); + uordblks = atomic_long_load(&heap->uordblks); if (uordblks <= usmblks) { break; } } - while (atomic_compare_exchange_weak(&heap->usmblks, &usmblks, uordblks)); + while (atomic_long_compare_exchange_weak(&heap->usmblks, + &usmblks, uordblks)); #if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0 if (mem == NULL && free_delaylist(heap, true)) @@ -486,19 +487,20 @@ void *mm_memalign(struct mm_heap_s *heap, size_t alignment, size_t size) size = host_mallocsize(mem); 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); + atomic_long_fetch_add(&heap->aordblks, 1); + atomic_long_fetch_add(&heap->uordblks, size); + usmblks = atomic_long_load(&heap->usmblks); do { - uordblks = atomic_load(&heap->uordblks); + uordblks = atomic_long_load(&heap->uordblks); if (uordblks <= usmblks) { break; } } - while (atomic_compare_exchange_weak(&heap->usmblks, &usmblks, uordblks)); + while (atomic_long_compare_exchange_weak(&heap->usmblks, + &usmblks, uordblks)); #if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0 if (mem == NULL && free_delaylist(heap, true)) @@ -573,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_long_load(&heap->aordblks); + info.uordblks = atomic_long_load(&heap->uordblks); + info.usmblks = atomic_long_load(&heap->usmblks); return info; } diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index f2d3c452fa354..68bf10c096554 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1180,8 +1180,8 @@ 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)) + atomic_long_fetch_sub(&dev->ibi->pending_ibis, 1); + if (!atomic_long_load(&dev->ibi->pending_ibis)) { sem_post(&dev->ibi->all_ibis_handled); } @@ -1800,7 +1800,7 @@ int i3c_master_add_i3c_dev_locked(FAR struct i3c_master_controller *master, void i3c_master_queue_ibi(FAR struct i3c_dev_desc *dev, FAR struct i3c_ibi_slot *slot) { - atomic_fetch_add(&dev->ibi->pending_ibis, 1); + atomic_long_fetch_add(&dev->ibi->pending_ibis, 1); work_queue(HPWORK, &slot->work, i3c_master_handle_ibi, slot, 0); } @@ -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_long_load(&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_long_init(&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 24fb868fb809e..7e88d074f3a83 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_long_load(&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_long_load(&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_long_store(&aw86225->exit_in_rtp_loop, 1); + while (atomic_long_load(&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_long_store(&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_long_store(&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_long_load(&aw86225->exit_in_rtp_loop)) { iinfo("%s: goint to waiting rtp exit\n", __func__); nxmutex_unlock(&aw86225->lock); diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c index cf5f65223ef87..301aa72a67421 100644 --- a/drivers/net/netdev_upperhalf.c +++ b/drivers/net/netdev_upperhalf.c @@ -155,7 +155,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 (atomic_fetch_sub(&upper->lower->quota[type], 1) <= 0) + if (atomic_long_fetch_sub(&upper->lower->quota[type], 1) <= 0) { nwarn("WARNING: Allowing temperarily exceeding quota of %s.\n", dev->d_ifname); @@ -187,7 +187,7 @@ static void netpkt_put(FAR struct net_driver_s *dev, FAR netpkt_t *pkt, * but we don't want these changes. */ - atomic_fetch_add(&upper->lower->quota[type], 1); + atomic_long_fetch_add(&upper->lower->quota[type], 1); netdev_iob_release(dev); dev->d_iob = pkt; dev->d_len = netpkt_getdatalen(upper->lower, pkt); @@ -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_long_load. * * 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_long_load(&dev->quota[type]); } /**************************************************************************** @@ -1403,16 +1403,16 @@ FAR netpkt_t *netpkt_alloc(FAR struct netdev_lowerhalf_s *dev, { FAR netpkt_t *pkt; - if (atomic_fetch_sub(&dev->quota[type], 1) <= 0) + if (atomic_long_fetch_sub(&dev->quota[type], 1) <= 0) { - atomic_fetch_add(&dev->quota[type], 1); + atomic_long_fetch_add(&dev->quota[type], 1); return NULL; } pkt = iob_tryalloc(false); if (pkt == NULL) { - atomic_fetch_add(&dev->quota[type], 1); + atomic_long_fetch_add(&dev->quota[type], 1); return NULL; } @@ -1436,7 +1436,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) { - atomic_fetch_add(&dev->quota[type], 1); + atomic_long_fetch_add(&dev->quota[type], 1); iob_free_chain(pkt); } diff --git a/drivers/note/notesnap_driver.c b/drivers/note/notesnap_driver.c index 636fc37f69e4c..272d26d6fe754 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_long_t index; + atomic_long_t dumping; struct notesnap_chunk_s buffer[CONFIG_DRIVERS_NOTESNAP_NBUFFERS]; }; @@ -212,14 +212,14 @@ 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_long_load(&snap->dumping)) { return; } /* Atomic operation, equivalent to snap.index++; */ - index = atomic_fetch_add(&snap->index, 1); + index = atomic_long_fetch_add(&snap->index, 1); note = &snap->buffer[index % CONFIG_DRIVERS_NOTESNAP_NBUFFERS]; note->type = type; @@ -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_long_store(&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_long_store(&g_notesnap.dumping, false); } /**************************************************************************** diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 665c6660ad532..a98a5185d968f 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -279,7 +279,7 @@ reset_control_get_internal(FAR struct reset_controller_dev *rcdev, return NULL; } - atomic_fetch_add(&rstc->refcnt, 1); + atomic_long_fetch_add(&rstc->refcnt, 1); return rstc; } } @@ -309,7 +309,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_long_init(&rstc->refcnt, 1); rstc->acquired = acquired; rstc->shared = shared; @@ -331,7 +331,7 @@ static void reset_control_put_internal(FAR struct reset_control *rstc) { DEBUGASSERT(nxmutex_is_locked(&g_reset_list_mutex)); - if (atomic_fetch_sub(&rstc->refcnt, 1) == 1) + if (atomic_long_fetch_sub(&rstc->refcnt, 1) == 1) { DEBUGASSERT(nxmutex_is_locked(&g_reset_list_mutex)); list_delete(&rstc->list); @@ -527,12 +527,12 @@ int reset_control_reset(FAR struct reset_control *rstc) if (rstc->shared) { - if (atomic_load(&rstc->deassert_count) != 0) + if (atomic_long_load(&rstc->deassert_count) != 0) { return -EINVAL; } - if (atomic_fetch_add(&rstc->triggered_count, 1) != 0) + if (atomic_long_fetch_add(&rstc->triggered_count, 1) != 0) { return 0; } @@ -551,7 +551,7 @@ int reset_control_reset(FAR struct reset_control *rstc) if (rstc->shared && ret < 0) { - atomic_fetch_sub(&rstc->triggered_count, 1); + atomic_long_fetch_sub(&rstc->triggered_count, 1); } return ret; @@ -597,18 +597,18 @@ int reset_control_assert(FAR struct reset_control *rstc) if (rstc->shared) { - if (atomic_load(&rstc->triggered_count) != 0) + if (atomic_long_load(&rstc->triggered_count) != 0) { return -EINVAL; } - if (atomic_load(&rstc->deassert_count) == 0) + if (atomic_long_load(&rstc->deassert_count) == 0) { rsterr("deassert_count = 0, invalid value\n"); return -EINVAL; } - if (atomic_fetch_sub(&rstc->deassert_count, 1) != 1) + if (atomic_long_fetch_sub(&rstc->deassert_count, 1) != 1) { return 0; } @@ -681,13 +681,13 @@ int reset_control_deassert(FAR struct reset_control *rstc) if (rstc->shared) { - if (atomic_load(&rstc->triggered_count) != 0) + if (atomic_long_load(&rstc->triggered_count) != 0) { rsterr("triggered_count != 0, invalid value\n"); return -EINVAL; } - if (atomic_fetch_add(&rstc->deassert_count, 1) != 0) + if (atomic_long_fetch_add(&rstc->deassert_count, 1) != 0) { return 0; } diff --git a/drivers/serial/pty.c b/drivers/serial/pty.c index 11e7855424f9a..1ec376db638ca 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_long_load(&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 a0042bfb0eca5..0a540bac6d8d6 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); + atomic_uint wroff = atomic_long_load(&buf->wroff); + atomic_uint rdoff = atomic_long_load(&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); + atomic_uint wroff = atomic_long_load(&buf->wroff); + atomic_uint rdoff = atomic_long_load(&buf->rdoff); return wroff >= rdoff ? wroff - rdoff : sizeof(buf->buffer) - rdoff + wroff; @@ -308,14 +308,14 @@ static int uart_ram_receive(FAR struct uart_dev_s *dev, FAR uint32_t *status) while (!uart_rambuf_rxavailable(priv->rx)); - rdoff = atomic_load(&priv->rx->rdoff); + rdoff = atomic_long_load(&priv->rx->rdoff); ch = priv->rx->buffer[rdoff]; if (++rdoff >= sizeof(priv->rx->buffer)) { rdoff = 0; } - atomic_store(&priv->rx->rdoff, rdoff); + atomic_long_store(&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_long_store(&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_long_store(&priv->rx->rdoff, dev->recv.tail); } /**************************************************************************** @@ -397,14 +397,14 @@ static void uart_ram_send(FAR struct uart_dev_s *dev, int ch) while (!uart_rambuf_txready(priv->tx)); - wroff = atomic_load(&priv->tx->wroff); + wroff = atomic_long_load(&priv->tx->wroff); priv->tx->buffer[wroff] = ch; if (++wroff >= sizeof(priv->tx->buffer)) { wroff = 0; } - atomic_store(&priv->tx->wroff, wroff); + atomic_long_store(&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_long_store(&rambuf[0].wroff, 0); + atomic_long_store(&rambuf[0].rdoff, 0); + atomic_long_store(&rambuf[1].wroff, 0); + atomic_long_store(&rambuf[1].rdoff, 0); if (slave) { diff --git a/drivers/wireless/bluetooth/bt_bridge.c b/drivers/wireless/bluetooth/bt_bridge.c index d53f62cfaa086..1a9dee5d42c68 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_long_t refs; bool dispatched[BT_FILTER_CMD_COUNT]; }; @@ -420,12 +420,12 @@ static int bt_bridge_open(FAR struct bt_driver_s *drv) FAR struct bt_bridge_s *bridge = device->bridge; FAR struct bt_driver_s *driver = bridge->driver; - if (atomic_fetch_add(&bridge->refs, 1) == 0) + if (atomic_long_fetch_add(&bridge->refs, 1) == 0) { int ret = driver->open(driver); if (ret < 0) { - atomic_fetch_sub(&bridge->refs, 1); + atomic_long_fetch_sub(&bridge->refs, 1); } return ret; @@ -514,7 +514,7 @@ static void bt_bridge_close(FAR struct bt_driver_s *drv) FAR struct bt_bridge_s *bridge = device->bridge; FAR struct bt_driver_s *driver = bridge->driver; - if (atomic_fetch_sub(&bridge->refs, 1) == 1) + if (atomic_long_fetch_sub(&bridge->refs, 1) == 1) { driver->close(driver); }; diff --git a/fs/event/event_close.c b/fs/event/event_close.c index 1749cf1eda558..5883a5a5857da 100644 --- a/fs/event/event_close.c +++ b/fs/event/event_close.c @@ -79,7 +79,7 @@ int nxevent_close(FAR nxevent_t *event) * now. */ - if (atomic_fetch_sub(&inode->i_crefs, 1) <= 1) + if (atomic_long_fetch_sub(&inode->i_crefs, 1) <= 1) { nxevent_destroy(&nevent->ne_event); group_free(NULL, nevent); diff --git a/fs/event/event_open.c b/fs/event/event_open.c index f0b2bf76c524d..3c234e06edc76 100644 --- a/fs/event/event_open.c +++ b/fs/event/event_open.c @@ -191,7 +191,7 @@ int nxevent_open(FAR nxevent_t **event, FAR const char *name, /* Initialize the inode */ INODE_SET_NAMEDEVENT(inode); - atomic_fetch_add(&inode->i_crefs, 1); + atomic_long_fetch_add(&inode->i_crefs, 1); /* Initialize the event groups */ diff --git a/fs/inode/fs_inodeaddref.c b/fs/inode/fs_inodeaddref.c index 240c0a07b7580..cf34966787b68 100644 --- a/fs/inode/fs_inodeaddref.c +++ b/fs/inode/fs_inodeaddref.c @@ -47,6 +47,6 @@ void inode_addref(FAR struct inode *inode) { if (inode) { - atomic_fetch_add(&inode->i_crefs, 1); + atomic_long_fetch_add(&inode->i_crefs, 1); } } diff --git a/fs/inode/fs_inodefind.c b/fs/inode/fs_inodefind.c index f53b502b4e2f6..eadab8382e338 100644 --- a/fs/inode/fs_inodefind.c +++ b/fs/inode/fs_inodefind.c @@ -68,7 +68,7 @@ int inode_find(FAR struct inode_search_s *desc) /* Increment the reference count on the inode */ - atomic_fetch_add(&inode->i_crefs, 1); + atomic_long_fetch_add(&inode->i_crefs, 1); } inode_runlock(); diff --git a/fs/inode/fs_inoderelease.c b/fs/inode/fs_inoderelease.c index 214fa98d59776..fd6938f1e4395 100644 --- a/fs/inode/fs_inoderelease.c +++ b/fs/inode/fs_inoderelease.c @@ -53,7 +53,7 @@ void inode_release(FAR struct inode *inode) { /* Decrement the references of the inode */ - if (atomic_fetch_sub(&inode->i_crefs, 1) <= 1) + if (atomic_long_fetch_sub(&inode->i_crefs, 1) <= 1) { DEBUGASSERT(inode->i_peer == NULL); inode_free(inode); diff --git a/fs/inode/fs_inoderemove.c b/fs/inode/fs_inoderemove.c index 792eabe0a5d17..d079b2ab7483a 100644 --- a/fs/inode/fs_inoderemove.c +++ b/fs/inode/fs_inoderemove.c @@ -98,7 +98,7 @@ static FAR struct inode *inode_unlink(FAR const char *path) inode->i_peer = NULL; inode->i_parent = NULL; - atomic_fetch_sub(&inode->i_crefs, 1); + atomic_long_fetch_sub(&inode->i_crefs, 1); } RELEASE_SEARCH(&desc); @@ -136,7 +136,7 @@ int inode_remove(FAR const char *path) * to it */ - if (atomic_load(&inode->i_crefs)) + if (atomic_long_load(&inode->i_crefs)) { return -EBUSY; } diff --git a/fs/inode/fs_inodereserve.c b/fs/inode/fs_inodereserve.c index 35fae49dd7fc6..fda68b515f526 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_long_init(&inode->i_crefs, 1); #ifdef CONFIG_PSEUDOFS_ATTRIBUTES inode->i_mode = mode; clock_gettime(CLOCK_REALTIME, &inode->i_atime); diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c index 1d852bee725a5..38fff13c5a222 100644 --- a/fs/mount/fs_mount.c +++ b/fs/mount/fs_mount.c @@ -420,7 +420,7 @@ int nx_mount(FAR const char *source, FAR const char *target, if (drvr_inode != NULL) #endif { - atomic_fetch_add(&drvr_inode->i_crefs, 1); + atomic_long_fetch_add(&drvr_inode->i_crefs, 1); } #endif @@ -448,7 +448,7 @@ int nx_mount(FAR const char *source, FAR const char *target, if (drvr_inode != NULL) #endif { - atomic_fetch_sub(&drvr_inode->i_crefs, 1); + atomic_long_fetch_sub(&drvr_inode->i_crefs, 1); } #endif diff --git a/fs/mount/fs_umount2.c b/fs/mount/fs_umount2.c index 546f6ff98fb2c..a059fca92515b 100644 --- a/fs/mount/fs_umount2.c +++ b/fs/mount/fs_umount2.c @@ -142,7 +142,7 @@ int nx_umount2(FAR const char *target, unsigned int flags) { /* Just decrement the reference count (without deleting it) */ - atomic_fetch_sub(&mountpt_inode->i_crefs, 1); + atomic_long_fetch_sub(&mountpt_inode->i_crefs, 1); inode_unlock(); } else diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c index d2e5cc79bc888..19b7a4edaec31 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_long_load(&inode->i_crefs) <= 0) { FAR struct mqueue_inode_s *msgq = inode->i_private; @@ -319,7 +319,7 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name, /* Set the initial reference count on this inode to one */ - atomic_fetch_add(&inode->i_crefs, 1); + atomic_long_fetch_add(&inode->i_crefs, 1); if (created) { diff --git a/fs/mqueue/mq_unlink.c b/fs/mqueue/mq_unlink.c index fb4d9d1550a40..49be986bfaef3 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_long_load(&inode->i_crefs) <= 1) { FAR struct mqueue_inode_s *msgq = inode->i_private; diff --git a/fs/semaphore/sem_close.c b/fs/semaphore/sem_close.c index 09bb257d00f36..b9cecb17670b1 100644 --- a/fs/semaphore/sem_close.c +++ b/fs/semaphore/sem_close.c @@ -87,7 +87,7 @@ int nxsem_close(FAR sem_t *sem) * now. */ - if (atomic_fetch_sub(&inode->i_crefs, 1) <= 1) + if (atomic_long_fetch_sub(&inode->i_crefs, 1) <= 1) { nxsem_destroy(&nsem->ns_sem); group_free(NULL, nsem); diff --git a/fs/semaphore/sem_open.c b/fs/semaphore/sem_open.c index cacccb2fc21a7..182ecf3a5db2c 100644 --- a/fs/semaphore/sem_open.c +++ b/fs/semaphore/sem_open.c @@ -208,7 +208,7 @@ int nxsem_open(FAR sem_t **sem, FAR const char *name, int oflags, ...) /* Initialize the inode */ INODE_SET_NAMEDSEM(inode); - atomic_fetch_add(&inode->i_crefs, 1); + atomic_long_fetch_add(&inode->i_crefs, 1); /* Initialize the semaphore */ diff --git a/fs/shm/shm_open.c b/fs/shm/shm_open.c index 1230585ee6bc6..3b8eed48448c1 100644 --- a/fs/shm/shm_open.c +++ b/fs/shm/shm_open.c @@ -145,7 +145,7 @@ static int file_shm_open(FAR struct file *shm, FAR const char *name, INODE_SET_SHM(inode); inode->u.i_ops = &g_shmfs_operations; inode->i_private = NULL; - atomic_fetch_add(&inode->i_crefs, 1); + atomic_long_fetch_add(&inode->i_crefs, 1); } /* Associate the inode with a file structure */ diff --git a/fs/shm/shmfs.c b/fs/shm/shmfs.c index 752e2d5dacdf9..f3a32b20676c7 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_long_load(&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_long_load(&inode->i_crefs) <= 1) { shmfs_free_object(inode->i_private); inode->i_private = NULL; diff --git a/fs/vfs/fs_dir.c b/fs/vfs/fs_dir.c index 585df77e14dcf..e8f097a643288 100644 --- a/fs/vfs/fs_dir.c +++ b/fs/vfs/fs_dir.c @@ -220,7 +220,7 @@ static off_t seek_pseudodir(FAR struct file *filep, off_t offset) { /* Increment the reference count on this next node */ - atomic_fetch_add(&curr->i_crefs, 1); + atomic_long_fetch_add(&curr->i_crefs, 1); } inode_unlock(); @@ -387,7 +387,7 @@ static int read_pseudodir(FAR struct fs_dirent_s *dir, { /* Increment the reference count on this next node */ - atomic_fetch_add(&pdir->next->i_crefs, 1); + atomic_long_fetch_add(&pdir->next->i_crefs, 1); } inode_unlock(); diff --git a/fs/vfs/fs_pseudofile.c b/fs/vfs/fs_pseudofile.c index 314c79eed8b19..575131bd22050 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_long_load(&inode->i_crefs) <= 1) { /* Delete the inode metadata */ diff --git a/include/nuttx/atomic.h b/include/nuttx/atomic.h index 1c430f963f9c1..768cd818c748e 100644 --- a/include/nuttx/atomic.h +++ b/include/nuttx/atomic.h @@ -86,13 +86,106 @@ extern "C++" # ifndef ATOMIC_VAR_INIT # define ATOMIC_VAR_INIT(value) (value) # endif -# else -# include # endif +#endif + +/**************************************************************************** + * 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 + +#if (ULONG_MAX == 0xFFFFFFFFUL) +# define ATOMIC_FUNC(a) a##4 #else -# include +# define ATOMIC_FUNC(a) a##8 #endif +#define atomic_long_store_explicit(obj, val, type) \ + ATOMIC_FUNC(__atomic_store_)(obj, val, type) +#define atomic_long_store(obj, val) \ + atomic_long_store_explicit(obj, val, __ATOMIC_RELAXED) +#define atomic_long_init(obj, val) atomic_long_store(obj, val) + +#define atomic_long_load_explicit(obj, type) \ + (long)ATOMIC_FUNC(__atomic_load_)(obj, type) +#define atomic_long_load(obj) \ + atomic_long_load_explicit(obj, __ATOMIC_RELAXED) + +#define atomic_long_exchange_explicit(obj, val, type) \ + (long)ATOMIC_FUNC(__atomic_exchange_)(obj, val, type) +#define atomic_long_exchange(obj, val) \ + atomic_long_exchange_explicit(obj, val, __ATOMIC_RELAXED) + +#define atomic_long_compare_exchange(obj, expected, desired, weak, success, failure) \ + ATOMIC_FUNC(__atomic_compare_exchange_)(obj, expected, desired, weak, success, failure) +#define atomic_long_compare_exchange_strong(obj, expected, desired) \ + atomic_long_compare_exchange(obj, expected, desired, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED) +#define atomic_long_compare_exchange_strong_explicit(obj, expected, desired, success, failure) \ + atomic_long_compare_exchange(obj, expected, desired, false, success, failure) +#define atomic_long_compare_exchange_weak(obj, expected, desired) \ + atomic_long_compare_exchange(obj, expected, desired, true, __ATOMIC_RELAXED, __ATOMIC_RELAXED) +#define atomic_long_compare_exchange_weak_explicit(obj, expected, desired, success, failure) \ + atomic_long_compare_exchange(obj, expected, desired, true, success, failure) + +#define atomic_long_flag_test_and_set_explicit(obj, type) \ + (long)ATOMIC_FUNC(__atomic_flags_test_and_set)(obj, type) +#define atomic_long_flag_test_and_set(obj) \ + atomic_long_flag_test_and_set_explicit(obj, __ATOMIC_RELAXED) + +#define atomic_long_fetch_add_explicit(obj, val, type) \ + (long)ATOMIC_FUNC(__atomic_fetch_add_)(obj, val, type) +#define atomic_long_fetch_add(obj, val) \ + atomic_long_fetch_add_explicit(obj, val, __ATOMIC_RELAXED) + +#define atomic_long_fetch_sub_explicit(obj, val, type) \ + (long)ATOMIC_FUNC(__atomic_fetch_sub_)(obj, val, type) +#define atomic_long_fetch_sub(obj, val) \ + atomic_long_fetch_sub_explicit(obj, val, __ATOMIC_RELAXED) + +#define atomic_long_fetch_and_explicit(obj, val, type) \ + (long)ATOMIC_FUNC(__atomic_fetch_and_)(obj, val, type) +#define atomic_long_fetch_and(obj, val) \ + atomic_long_fetch_and_explicit(obj, val, __ATOMIC_RELAXED) + +#define atomic_long_fetch_or_explicit(obj, val, type) \ + (long)ATOMIC_FUNC(__atomic_fetch_or_)(obj, val, type) +#define atomic_long_fetch_or(obj, val) \ + atomic_long_fetch_or_explicit(obj, val, __ATOMIC_RELAXED) + +#define atomic_long_fetch_xor_explicit(obj, val, type) \ + (long)ATOMIC_FUNC(__atomic_fetch_xor_)(obj, val, type) +#define atomic_long_fetch_xor(obj, val) \ + atomic_long_fetch_xor_explicit(obj, val, __ATOMIC_RELAXED) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +typedef volatile long atomic_long_t; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index d9aa023b8383b..040ed17aa2eb2 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -403,7 +403,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_long_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/lib/stdatomic.h b/include/nuttx/lib/stdatomic.h deleted file mode 100644 index 48972b61ae7fd..0000000000000 --- 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 bf56e0f26718c..dc51b94721c2e 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_long_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 9d5d908b79654..3936137cba596 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_long_t refcnt; bool acquired; bool shared; bool array; - atomic_int deassert_count; - atomic_int triggered_count; + atomic_long_t deassert_count; + atomic_long_t triggered_count; }; /**************************************************************************** diff --git a/include/nuttx/serial/uart_ram.h b/include/nuttx/serial/uart_ram.h index 04cff1b1f032f..824c4131b83e5 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_long_t wroff; + atomic_long_t rdoff; }; /**************************************************************************** diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index bd15818d6a7e7..35536538bce94 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -244,8 +244,8 @@ 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) + atomic_long_fetch_add(&lock->tickets.next, 1); + while (atomic_long_load(&lock->tickets.owner) != ticket) #else /* CONFIG_TICKET_SPINLOCK */ while (up_testset(lock) == SP_LOCKED) #endif @@ -326,7 +326,7 @@ spin_trylock_wo_note(FAR volatile spinlock_t *lock) { #ifdef CONFIG_TICKET_SPINLOCK unsigned short ticket = - atomic_load((FAR atomic_ushort *)&lock->tickets.next); + atomic_long_load(&lock->tickets.next); spinlock_t oldval = { @@ -342,8 +342,9 @@ spin_trylock_wo_note(FAR volatile spinlock_t *lock) } }; - if (!atomic_compare_exchange_strong((FAR atomic_uint *)&lock->value, - &oldval.value, newval.value)) + if (!atomic_long_compare_exchange_strong(&lock->value, + &oldval.value, + newval.value)) #else /* CONFIG_TICKET_SPINLOCK */ if (up_testset(lock) == SP_LOCKED) #endif /* CONFIG_TICKET_SPINLOCK */ @@ -431,7 +432,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_long_fetch_add(&lock->tickets.owner, 1); #else *lock = SP_UNLOCKED; #endif @@ -813,15 +814,16 @@ static inline_function void read_lock(FAR volatile rwlock_t *lock) { while (true) { - int old = atomic_load((FAR atomic_int *)lock); + long old = atomic_long_load(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_long_compare_exchange_strong(lock, + &old, + old + 1)) { break; } @@ -858,14 +860,15 @@ static inline_function bool read_trylock(FAR volatile rwlock_t *lock) { while (true) { - int old = atomic_load((FAR atomic_int *)lock); + long old = atomic_long_load(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_long_compare_exchange_strong(lock, + &old, + old + 1)) { break; } @@ -894,10 +897,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_long_load(lock) >= RW_SP_READ_LOCKED); SP_DMB(); - atomic_fetch_sub((FAR atomic_int *)lock, 1); + atomic_long_fetch_sub(lock, 1); SP_DSB(); SP_SEV(); } @@ -931,8 +934,8 @@ 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_long_compare_exchange_strong(lock, + &zero, RW_SP_WRITE_LOCKED)) { SP_DSB(); SP_WFE(); @@ -970,8 +973,8 @@ 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_long_compare_exchange_strong(lock, + &zero, RW_SP_WRITE_LOCKED)) { SP_DMB(); return true; @@ -1002,10 +1005,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_long_load(lock) == RW_SP_WRITE_LOCKED); SP_DMB(); - atomic_store((FAR atomic_int *)lock, RW_SP_UNLOCKED); + atomic_long_store(lock, RW_SP_UNLOCKED); SP_DSB(); SP_SEV(); } diff --git a/include/semaphore.h b/include/semaphore.h index bfd96cab57a81..ffb6fe2839b08 100644 --- a/include/semaphore.h +++ b/include/semaphore.h @@ -33,6 +33,7 @@ #include #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -104,7 +105,7 @@ struct semholder_s struct sem_s { - volatile int16_t semcount; /* >0 -> Num counts available */ + atomic_long_t semcount; /* >0 -> Num counts available */ /* <0 -> Num tasks waiting for semaphore */ /* If priority inheritance is enabled, then we have to keep track of which diff --git a/libs/libc/machine/arch_atomic.c b/libs/libc/machine/arch_atomic.c index bdecc8c057f69..b03e4cbe113f9 100644 --- a/libs/libc/machine/arch_atomic.c +++ b/libs/libc/machine/arch_atomic.c @@ -323,280 +323,240 @@ ****************************************************************************/ 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) /**************************************************************************** * Name: __atomic_store_8 ****************************************************************************/ STORE(__atomic_store_, 8, uint64_t) -STORE(nx_atomic_store_, 8, uint64_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) /**************************************************************************** * Name: __atomic_load__8 ****************************************************************************/ LOAD(__atomic_load_, 8, uint64_t) -LOAD(nx_atomic_load_, 8, uint64_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) /**************************************************************************** * Name: __atomic_exchange__8 ****************************************************************************/ EXCHANGE(__atomic_exchange_, 8, uint64_t) -EXCHANGE(nx_atomic_exchange_, 8, uint64_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) /**************************************************************************** * Name: __atomic_compare_exchange_8 ****************************************************************************/ CMP_EXCHANGE(__atomic_compare_exchange_, 8, uint64_t) -CMP_EXCHANGE(nx_atomic_compare_exchange_, 8, uint64_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) /**************************************************************************** * 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) /**************************************************************************** * 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) /**************************************************************************** * Name: __atomic_fetch_add_8 ****************************************************************************/ FETCH_ADD(__atomic_fetch_add_, 8, uint64_t) -FETCH_ADD(nx_atomic_fetch_add_, 8, uint64_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) /**************************************************************************** * Name: __atomic_fetch_sub_8 ****************************************************************************/ FETCH_SUB(__atomic_fetch_sub_, 8, uint64_t) -FETCH_SUB(nx_atomic_fetch_sub_, 8, uint64_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) /**************************************************************************** * Name: __atomic_fetch_and_8 ****************************************************************************/ FETCH_AND(__atomic_fetch_and_, 8, uint64_t) -FETCH_AND(nx_atomic_fetch_and_, 8, uint64_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) /**************************************************************************** * Name: __atomic_fetch_or_4 ****************************************************************************/ FETCH_OR(__atomic_fetch_or_, 8, uint64_t) -FETCH_OR(nx_atomic_fetch_or_, 8, uint64_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) /**************************************************************************** * Name: __atomic_fetch_xor_8 ****************************************************************************/ FETCH_XOR(__atomic_fetch_xor_, 8, uint64_t) -FETCH_XOR(nx_atomic_fetch_xor_, 8, uint64_t) /* Clang define the __sync builtins, add #ifndef to avoid * redefined/redeclared problem. @@ -609,224 +569,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/sched/semaphore/sem_destroy.c b/sched/semaphore/sem_destroy.c index fa94ef92ad456..aeb7e842816a2 100644 --- a/sched/semaphore/sem_destroy.c +++ b/sched/semaphore/sem_destroy.c @@ -60,7 +60,7 @@ int nxsem_destroy(FAR sem_t *sem) { - short old; + long old; DEBUGASSERT(sem != NULL); @@ -76,16 +76,16 @@ int nxsem_destroy(FAR sem_t *sem) do { - old = atomic_load(NXSEM_COUNT(sem)); + old = atomic_long_load(NXSEM_COUNT(sem)); if (old < 0) { break; } } - while (!atomic_compare_exchange_weak_explicit(NXSEM_COUNT(sem), + while (!atomic_long_compare_exchange_weak_explicit(NXSEM_COUNT(sem), &old, 1, - memory_order_release, - memory_order_relaxed)); + __ATOMIC_RELEASE, + __ATOMIC_RELAXED)); /* Release holders of the semaphore */ diff --git a/sched/semaphore/sem_holder.c b/sched/semaphore/sem_holder.c index 1da9f3e2a94de..a61d542a9e564 100644 --- a/sched/semaphore/sem_holder.c +++ b/sched/semaphore/sem_holder.c @@ -880,7 +880,7 @@ void nxsem_canceled(FAR struct tcb_s *stcb, FAR sem_t *sem) { /* Check our assumptions */ - DEBUGASSERT(atomic_load(NXSEM_COUNT(sem)) <= 0); + DEBUGASSERT(atomic_long_load(NXSEM_COUNT(sem)) <= 0); /* Adjust the priority of every holder as necessary */ @@ -978,7 +978,7 @@ void nxsem_release_all(FAR struct tcb_s *htcb) * that was taken by sem_wait() or sem_post(). */ - atomic_fetch_add(NXSEM_COUNT(sem), 1); + atomic_long_fetch_add(NXSEM_COUNT(sem), 1); } } diff --git a/sched/semaphore/sem_post.c b/sched/semaphore/sem_post.c index 500b00f5954ce..dfa4352e88005 100644 --- a/sched/semaphore/sem_post.c +++ b/sched/semaphore/sem_post.c @@ -85,13 +85,13 @@ static int nxsem_post_slow(FAR sem_t *sem) flags = enter_critical_section(); - sem_count = atomic_fetch_add(NXSEM_COUNT(sem), 1); + sem_count = atomic_long_fetch_add(NXSEM_COUNT(sem), 1); /* Check the maximum allowable value */ if (sem_count >= SEM_VALUE_MAX) { - atomic_fetch_sub(NXSEM_COUNT(sem), 1); + atomic_long_fetch_sub(NXSEM_COUNT(sem), 1); leave_critical_section(flags); return -EOVERFLOW; } @@ -259,10 +259,11 @@ int nxsem_post(FAR sem_t *sem) #if !defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_PRIORITY_PROTECT) if (sem->flags & SEM_TYPE_MUTEX) { - short old = 0; - if (atomic_compare_exchange_weak_explicit(NXSEM_COUNT(sem), &old, 1, - memory_order_release, - memory_order_relaxed)) + long old = 0; + if (atomic_long_compare_exchange_weak_explicit(NXSEM_COUNT(sem), + &old, 1, + __ATOMIC_RELEASE, + __ATOMIC_RELAXED)) { return OK; } diff --git a/sched/semaphore/sem_recover.c b/sched/semaphore/sem_recover.c index dd0418d4bbdce..27a7497303066 100644 --- a/sched/semaphore/sem_recover.c +++ b/sched/semaphore/sem_recover.c @@ -85,7 +85,7 @@ void nxsem_recover(FAR struct tcb_s *tcb) if (tcb->task_state == TSTATE_WAIT_SEM) { FAR sem_t *sem = tcb->waitobj; - DEBUGASSERT(sem != NULL && atomic_load(NXSEM_COUNT(sem)) < 0); + DEBUGASSERT(sem != NULL && atomic_long_load(NXSEM_COUNT(sem)) < 0); /* Restore the correct priority of all threads that hold references * to this semaphore. @@ -99,7 +99,7 @@ void nxsem_recover(FAR struct tcb_s *tcb) * place. */ - atomic_fetch_add(NXSEM_COUNT(sem), 1); + atomic_long_fetch_add(NXSEM_COUNT(sem), 1); } /* Release all semphore holders for the task */ diff --git a/sched/semaphore/sem_reset.c b/sched/semaphore/sem_reset.c index d7774ea504291..07c494f70e417 100644 --- a/sched/semaphore/sem_reset.c +++ b/sched/semaphore/sem_reset.c @@ -60,7 +60,7 @@ int nxsem_reset(FAR sem_t *sem, int16_t count) { irqstate_t flags; - short semcount; + long semcount; DEBUGASSERT(sem != NULL && count >= 0); @@ -81,7 +81,7 @@ int nxsem_reset(FAR sem_t *sem, int16_t count) * out counts to any waiting threads. */ - while (atomic_load(NXSEM_COUNT(sem)) < 0 && count > 0) + while (atomic_long_load(NXSEM_COUNT(sem)) < 0 && count > 0) { /* Give out one counting, waking up one of the waiting threads * and, perhaps, kicking off a lot of priority inheritance @@ -101,16 +101,16 @@ int nxsem_reset(FAR sem_t *sem, int16_t count) do { - semcount = atomic_load(NXSEM_COUNT(sem)); + semcount = atomic_long_load(NXSEM_COUNT(sem)); if (semcount < 0) { break; } } - while (!atomic_compare_exchange_weak_explicit(NXSEM_COUNT(sem), - &semcount, count, - memory_order_release, - memory_order_relaxed)); + while (!atomic_long_compare_exchange_weak_explicit(NXSEM_COUNT(sem), + &semcount, count, + __ATOMIC_RELEASE, + __ATOMIC_RELAXED)); /* Allow any pending context switches to occur now */ diff --git a/sched/semaphore/sem_trywait.c b/sched/semaphore/sem_trywait.c index c4b512547bd7f..9049c01a67ace 100644 --- a/sched/semaphore/sem_trywait.c +++ b/sched/semaphore/sem_trywait.c @@ -64,7 +64,7 @@ static int nxsem_trywait_slow(FAR sem_t *sem) { FAR struct tcb_s *rtcb; irqstate_t flags; - short semcount; + long semcount; int ret; /* The following operations must be performed with interrupts disabled @@ -78,24 +78,24 @@ static int nxsem_trywait_slow(FAR sem_t *sem) do { - semcount = atomic_load(NXSEM_COUNT(sem)); + semcount = atomic_long_load(NXSEM_COUNT(sem)); if (semcount <= 0) { leave_critical_section(flags); return -EAGAIN; } } - while (!atomic_compare_exchange_weak_explicit(NXSEM_COUNT(sem), + while (!atomic_long_compare_exchange_weak_explicit(NXSEM_COUNT(sem), &semcount, semcount - 1, - memory_order_acquire, - memory_order_relaxed)); + __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED)); /* It is, let the task take the semaphore */ ret = nxsem_protect_wait(sem); if (ret < 0) { - atomic_fetch_add(NXSEM_COUNT(sem), 1); + atomic_long_fetch_add(NXSEM_COUNT(sem), 1); leave_critical_section(flags); return ret; } @@ -153,10 +153,11 @@ int nxsem_trywait(FAR sem_t *sem) #if !defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_PRIORITY_PROTECT) if (sem->flags & SEM_TYPE_MUTEX) { - short old = 1; - if (atomic_compare_exchange_weak_explicit(NXSEM_COUNT(sem), &old, 0, - memory_order_acquire, - memory_order_relaxed)) + long old = 1; + if (atomic_long_compare_exchange_weak_explicit(NXSEM_COUNT(sem), + &old, 0, + __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED)) { return OK; } diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c index a0a8b9d76f177..c4d8e9b6c00ee 100644 --- a/sched/semaphore/sem_wait.c +++ b/sched/semaphore/sem_wait.c @@ -85,7 +85,7 @@ static int nxsem_wait_slow(FAR sem_t *sem) /* Check if the lock is available */ - if (atomic_fetch_sub(NXSEM_COUNT(sem), 1) > 0) + if (atomic_long_fetch_sub(NXSEM_COUNT(sem), 1) > 0) { /* It is, let the task take the semaphore. */ @@ -259,10 +259,11 @@ int nxsem_wait(FAR sem_t *sem) #if !defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_PRIORITY_PROTECT) if (sem->flags & SEM_TYPE_MUTEX) { - short old = 1; - if (atomic_compare_exchange_weak_explicit(NXSEM_COUNT(sem), &old, 0, - memory_order_acquire, - memory_order_relaxed)) + long old = 1; + if (atomic_long_compare_exchange_weak_explicit(NXSEM_COUNT(sem), + &old, 0, + __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED)) { return OK; } diff --git a/sched/semaphore/sem_waitirq.c b/sched/semaphore/sem_waitirq.c index e3cd08db1825d..5113c4817bdc4 100644 --- a/sched/semaphore/sem_waitirq.c +++ b/sched/semaphore/sem_waitirq.c @@ -87,7 +87,7 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode) * and already changed the task's state. */ - DEBUGASSERT(sem != NULL && atomic_load(NXSEM_COUNT(sem)) < 0); + DEBUGASSERT(sem != NULL && atomic_long_load(NXSEM_COUNT(sem)) < 0); /* Restore the correct priority of all threads that hold references * to this semaphore. @@ -101,7 +101,7 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode) * place. */ - atomic_fetch_add(NXSEM_COUNT(sem), 1); + atomic_long_fetch_add(NXSEM_COUNT(sem), 1); /* Remove task from waiting list */ diff --git a/sched/semaphore/semaphore.h b/sched/semaphore/semaphore.h index 45f745f58bc26..9673becef0219 100644 --- a/sched/semaphore/semaphore.h +++ b/sched/semaphore/semaphore.h @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -40,7 +39,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define NXSEM_COUNT(s) ((FAR atomic_short *)&(s)->semcount) +#define NXSEM_COUNT(s) (&(s)->semcount) /**************************************************************************** * Public Function Prototypes