Skip to content

Commit

Permalink
arch_atomic: nx only use atomic int type
Browse files Browse the repository at this point in the history
Modify the kernel to use only the int type atomic 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 <[email protected]>
  • Loading branch information
zyfeier committed Nov 18, 2024
1 parent a88652f commit 7e573ba
Show file tree
Hide file tree
Showing 40 changed files with 264 additions and 491 deletions.
2 changes: 1 addition & 1 deletion arch/arm/src/cxd56xx/cxd56_sph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/src/cxd56xx/cxd56_uart0.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion arch/sim/src/sim/posix/sim_testset.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ uint8_t up_testset(volatile uint8_t *lock)
* following test and set is atomic.
*/

return atomic_exchange((_Atomic uint8_t *)lock, 1);
return atomic_xchg((_Atomic uint8_t *)lock, 1);
#else

/* In the non-SMP case, the simulation is implemented with a single thread
Expand Down
26 changes: 14 additions & 12 deletions arch/sim/src/sim/sim_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_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;
Expand Down Expand Up @@ -385,7 +385,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)
Expand All @@ -398,13 +398,14 @@ 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))
Expand Down Expand Up @@ -488,17 +489,18 @@ 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))
Expand Down Expand Up @@ -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_read(&heap->aordblks);
info.uordblks = atomic_read(&heap->uordblks);
info.usmblks = atomic_read(&heap->usmblks);
return info;
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/i3c/master.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions drivers/input/aw86225.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1121,24 +1121,24 @@ 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__);

ret = nxsem_wait(&aw86225->wait_q);

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__);
return;
}
}

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);

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/netdev_upperhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]);
}

/****************************************************************************
Expand Down
10 changes: 5 additions & 5 deletions drivers/note/notesnap_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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++)
{
Expand All @@ -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);
}

/****************************************************************************
Expand Down
10 changes: 5 additions & 5 deletions drivers/reset/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions drivers/rpmsg/rpmsg_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include <stdbool.h>

#include <metal/atomic.h>
#include <nuttx/atomic.h>

#include <nuttx/list.h>
#include <nuttx/spinlock.h>
Expand Down Expand Up @@ -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);
}

/****************************************************************************
Expand All @@ -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);
}

/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion drivers/rpmsg/rpmsg_port_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/rpmsg/rpmsg_port_spi_slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion drivers/serial/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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? */

Expand Down
Loading

0 comments on commit 7e573ba

Please sign in to comment.