From 8b5ea40a2b38344a3c1e92af90cfc4ccf3fd48aa Mon Sep 17 00:00:00 2001 From: wangzhi16 Date: Mon, 20 Jan 2025 17:24:51 +0800 Subject: [PATCH] Use small lock to protect resources related to cpufifo. Signed-off-by: wangzhi16 --- arch/arm/src/cxd56xx/cxd56_cpufifo.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/arm/src/cxd56xx/cxd56_cpufifo.c b/arch/arm/src/cxd56xx/cxd56_cpufifo.c index 860a5207dfe..474205a4ff1 100644 --- a/arch/arm/src/cxd56xx/cxd56_cpufifo.c +++ b/arch/arm/src/cxd56xx/cxd56_cpufifo.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -79,6 +80,7 @@ static sq_queue_t g_pushqueue; static sq_queue_t g_emptyqueue; static struct cfpushdata_s g_pushbuffer[NR_PUSHBUFENTRIES]; static cpufifo_handler_t g_cfrxhandler; +static spinlock_t g_cpufifo_lock = SP_UNLOCKED; /**************************************************************************** * Private Functions @@ -175,11 +177,11 @@ int cxd56_cfpush(uint32_t data[2]) irqstate_t flags; int ret; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_cpufifo_lock); if (!sq_empty(&g_pushqueue)) { ret = cpufifo_reserve(data); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_cpufifo_lock, flags); return ret; } @@ -190,7 +192,7 @@ int cxd56_cfpush(uint32_t data[2]) up_enable_irq(CXD56_IRQ_FIFO_TO); } - leave_critical_section(flags); + spin_unlock_irqrestore(&g_cpufifo_lock, flags); return OK; } @@ -214,7 +216,7 @@ int cxd56_cfregrxhandler(cpufifo_handler_t handler) irqstate_t flags; int ret = OK; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_cpufifo_lock); if (g_cfrxhandler) { ret = -1; @@ -224,16 +226,16 @@ int cxd56_cfregrxhandler(cpufifo_handler_t handler) g_cfrxhandler = handler; } - leave_critical_section(flags); + spin_unlock_irqrestore(&g_cpufifo_lock, flags); return ret; } void cxd56_cfunregrxhandler(void) { irqstate_t flags; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_cpufifo_lock); g_cfrxhandler = NULL; - leave_critical_section(flags); + spin_unlock_irqrestore(&g_cpufifo_lock, flags); } int cxd56_cfinitialize(void)