Revert "use small lock in following files:"

This reverts commit d84ba608a1.
This commit is contained in:
Xiang Xiao 2025-02-06 23:04:51 +08:00 committed by archer
parent 6c7b440f47
commit 31e92f3bb5
10 changed files with 62 additions and 108 deletions

View file

@ -27,11 +27,9 @@
#include <nuttx/config.h>
#include <assert.h>
#include <sched.h>
#include <arch/board/board.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/arch.h>
#include <nuttx/can/can.h>
@ -207,8 +205,6 @@ static struct can_dev_s g_can1dev =
};
#endif
static spinlock_t g_can_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -1083,8 +1079,7 @@ struct can_dev_s *am335x_can_initialize(int port)
syslog(LOG_DEBUG, "CAN%d\n", port);
flags = spin_lock_irqsave(&g_can_lock);
sched_lock();
flags = enter_critical_section();
#ifdef CONFIG_AM335X_CAN0
if (port == 0)
@ -1114,13 +1109,11 @@ struct can_dev_s *am335x_can_initialize(int port)
{
canerr("Unsupported port: %d\n", port);
spin_unlock_irqrestore(&g_can_lock, flags);
sched_unlock();
leave_critical_section(flags);
return NULL;
}
spin_unlock_irqrestore(&g_can_lock, flags);
sched_unlock();
leave_critical_section(flags);
return candev;
}
@ -1131,8 +1124,7 @@ void am335x_can_uninitialize(struct can_dev_s *dev)
DEBUGASSERT(dev);
flags = spin_lock_irqsave(&g_can_lock);
sched_lock();
flags = enter_critical_section();
#ifdef CONFIG_AM335X_CAN0
if (dev == &g_can0dev)
@ -1159,8 +1151,7 @@ void am335x_can_uninitialize(struct can_dev_s *dev)
canerr("Not a CAN device: %p\n", dev);
}
spin_unlock_irqrestore(&g_can_lock, flags);
sched_unlock();
leave_critical_section(flags);
}
#endif

View file

@ -31,7 +31,6 @@
#include <errno.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include "chip.h"
#include "arm_internal.h"
@ -220,8 +219,6 @@ static const uint8_t *g_gpio_padctl[AM335X_GPIO_NPORTS] =
g_gpio3_padctl, /* GPIO3 */
};
static spinlock_t g_gpio_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -367,7 +364,7 @@ int am335x_gpio_config(gpio_pinset_t pinset)
/* Configure the pin as an input initially to avoid any spurious outputs */
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
/* Configure based upon the pin mode */
@ -410,7 +407,7 @@ int am335x_gpio_config(gpio_pinset_t pinset)
break;
}
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
return ret;
}
@ -428,9 +425,9 @@ void am335x_gpio_write(gpio_pinset_t pinset, bool value)
int port = (pinset & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT;
int pin = (pinset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT;
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
am335x_gpio_setoutput(port, pin, value);
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
}
/****************************************************************************
@ -448,9 +445,9 @@ bool am335x_gpio_read(gpio_pinset_t pinset)
int pin = (pinset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT;
bool value;
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
value = am335x_gpio_getinput(port, pin);
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
return value;
}

View file

@ -37,7 +37,6 @@
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
@ -186,7 +185,6 @@ struct am335x_i2c_priv_s
int refs; /* Reference count */
mutex_t lock; /* Mutual exclusion mutex */
spinlock_t spinlock; /* Spinlock */
#ifndef CONFIG_I2C_POLLED
sem_t sem_isr; /* Interrupt wait semaphore */
#endif
@ -319,7 +317,6 @@ static struct am335x_i2c_priv_s am335x_i2c0_priv =
.config = &am335x_i2c0_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
@ -355,7 +352,6 @@ static struct am335x_i2c_priv_s am335x_i2c1_priv =
.config = &am335x_i2c1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
@ -391,7 +387,6 @@ static struct am335x_i2c_priv_s am335x_i2c2_priv =
.config = &am335x_i2c2_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
@ -497,7 +492,7 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
uint32_t regval;
int ret;
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
/* Enable Interrupts when master mode */
@ -534,8 +529,6 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
*/
priv->intstate = INTSTATE_WAITING;
spin_unlock_irqrestore(&priv->spinlock, flags);
do
{
/* Wait until either the transfer is complete or the timeout expires */
@ -558,8 +551,6 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
}
}
flags = spin_lock_irqsave(&priv->spinlock);
/* Loop until the interrupt level transfer is complete. */
while (priv->intstate != INTSTATE_DONE);
@ -572,7 +563,7 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
am335x_i2c_putreg(priv, AM335X_I2C_IRQ_EN_CLR_OFFSET, I2C_ICR_CLEARMASK);
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
return ret;
}
#else
@ -1001,7 +992,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
*/
#ifdef CONFIG_I2C_POLLED
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
irqstate_t flags = enter_critical_section();
#endif
/* Transmit a byte */
@ -1010,7 +1001,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
priv->dcnt--;
#ifdef CONFIG_I2C_POLLED
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
#endif
if ((priv->dcnt == 0) && ((priv->flags & I2C_M_NOSTOP) == 0))
{
@ -1035,7 +1026,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
*/
#ifdef CONFIG_I2C_POLLED
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
irqstate_t flags = enter_critical_section();
#endif
/* Receive a byte */
@ -1045,7 +1036,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
priv->dcnt--;
#ifdef CONFIG_I2C_POLLED
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
#endif
if ((priv->msgc <= 0) && (priv->dcnt == 0))
{
@ -1109,7 +1100,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
*/
#ifdef CONFIG_I2C_POLLED
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
irqstate_t flags = enter_critical_section();
#endif
/* Transmit a byte */
@ -1118,7 +1109,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
priv->dcnt--;
#ifdef CONFIG_I2C_POLLED
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
#endif
if ((priv->dcnt == 0) && ((priv->flags & I2C_M_NOSTOP) == 0))
{

View file

@ -29,7 +29,6 @@
#include <assert.h>
#include <nuttx/arch.h>
#include <nuttx/spinlock.h>
#include "arm_internal.h"
#include "sctlr.h"
@ -37,13 +36,6 @@
#include "am335x_gpio.h"
#include "am335x_irq.h"
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_ARCH_IRQPRIO
static spinlock_t g_irq_lock = SP_UNLOCKED;
#endif
/****************************************************************************
* Public Data
****************************************************************************/
@ -336,7 +328,7 @@ int up_prioritize_irq(int irq, int priority)
{
/* These operations must be atomic */
flags = spin_lock_irqsave(&g_irq_lock);
flags = enter_critical_section();
#if 0 // TODO
/* Set the new priority */
@ -348,7 +340,7 @@ int up_prioritize_irq(int irq, int priority)
putreg32(regval, regaddr);
#endif
spin_unlock_irqrestore(&g_irq_lock, flags);
leave_critical_section(flags);
return OK;
}

View file

@ -39,7 +39,6 @@
#endif
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/arch.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/serial.h>
@ -77,14 +76,13 @@
struct up_dev_s
{
uint32_t uartbase; /* Base address of UART registers */
uint32_t baud; /* Configured baud */
uint32_t ier; /* Saved IER value */
uint8_t irq; /* IRQ associated with this UART */
uint8_t parity; /* 0=none, 1=odd, 2=even */
uint8_t bits; /* Number of bits (7 or 8) */
bool stopbits2; /* true: Configure with 2 stop bits instead of 1 */
spinlock_t spinlock; /* Spinlock */
uint32_t uartbase; /* Base address of UART registers */
uint32_t baud; /* Configured baud */
uint32_t ier; /* Saved IER value */
uint8_t irq; /* IRQ associated with this UART */
uint8_t parity; /* 0=none, 1=odd, 2=even */
uint8_t bits; /* Number of bits (7 or 8) */
bool stopbits2; /* true: Configure with 2 stop bits instead of 1 */
};
/****************************************************************************
@ -171,7 +169,6 @@ static struct up_dev_s g_uart0priv =
.parity = CONFIG_UART0_PARITY,
.bits = CONFIG_UART0_BITS,
.stopbits2 = CONFIG_UART0_2STOP,
.spinlock = SP_UNLOCKED,
};
static uart_dev_t g_uart0port =
@ -203,7 +200,6 @@ static struct up_dev_s g_uart1priv =
.parity = CONFIG_UART1_PARITY,
.bits = CONFIG_UART1_BITS,
.stopbits2 = CONFIG_UART1_2STOP,
.spinlock = SP_UNLOCKED,
};
static uart_dev_t g_uart1port =
@ -234,7 +230,6 @@ static struct up_dev_s g_uart2priv =
.parity = CONFIG_UART2_PARITY,
.bits = CONFIG_UART2_BITS,
.stopbits2 = CONFIG_UART2_2STOP,
.spinlock = SP_UNLOCKED,
};
static uart_dev_t g_uart2port =
@ -265,7 +260,6 @@ static struct up_dev_s g_uart3priv =
.parity = CONFIG_UART3_PARITY,
.bits = CONFIG_UART3_BITS,
.stopbits2 = CONFIG_UART3_2STOP,
.spinlock = SP_UNLOCKED,
};
static uart_dev_t g_uart3port =
@ -296,7 +290,6 @@ static struct up_dev_s g_uart4priv =
.parity = CONFIG_UART4_PARITY,
.bits = CONFIG_UART4_BITS,
.stopbits2 = CONFIG_UART4_2STOP,
.spinlock = SP_UNLOCKED,
};
static uart_dev_t g_uart4port =
@ -327,7 +320,6 @@ static struct up_dev_s g_uart5priv =
.parity = CONFIG_UART5_PARITY,
.bits = CONFIG_UART5_BITS,
.stopbits2 = CONFIG_UART5_2STOP,
.spinlock = SP_UNLOCKED,
};
static uart_dev_t g_uart5port =
@ -492,10 +484,6 @@ static uart_dev_t g_uart5port =
# define UART5_ASSIGNED 1
#endif
/* Spinlock */
static spinlock_t g_gpio_lock = SP_UNLOCKED;
/****************************************************************************
* Inline Functions
****************************************************************************/
@ -579,7 +567,7 @@ static inline void am335x_uart0config(void)
/* Step 1: Enable power to UART0 */
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
#warning Missing logic
/* Step 2: Enable clocking to UART0 */
@ -589,7 +577,7 @@ static inline void am335x_uart0config(void)
am335x_gpio_config(GPIO_UART0_TXD);
am335x_gpio_config(GPIO_UART0_RXD);
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
};
#endif
@ -600,7 +588,7 @@ static inline void am335x_uart1config(void)
/* Step 1: Enable power to UART1 */
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
#warning Missing logic
/* Step 2: Enable clocking to UART1 */
@ -610,7 +598,7 @@ static inline void am335x_uart1config(void)
am335x_gpio_config(GPIO_UART1_TXD);
am335x_gpio_config(GPIO_UART1_RXD);
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
};
#endif
@ -621,7 +609,7 @@ static inline void am335x_uart2config(void)
/* Step 1: Enable power to UART2 */
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
#warning Missing logic
/* Step 2: Enable clocking on UART2 */
@ -631,7 +619,7 @@ static inline void am335x_uart2config(void)
am335x_gpio_config(GPIO_UART2_TXD);
am335x_gpio_config(GPIO_UART2_RXD);
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
};
#endif
@ -642,7 +630,7 @@ static inline void am335x_uart3config(void)
/* Step 1: Enable power to UART3 */
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
#warning Missing logic
/* Step 2: Enable clocking to UART3 */
@ -652,7 +640,7 @@ static inline void am335x_uart3config(void)
am335x_gpio_config(GPIO_UART3_TXD);
am335x_gpio_config(GPIO_UART3_RXD);
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
};
#endif
@ -663,7 +651,7 @@ static inline void am335x_uart4config(void)
/* Step 1: Enable power to UART4 */
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
#warning Missing logic
/* Step 2: Enable clocking to UART4 */
@ -673,7 +661,7 @@ static inline void am335x_uart4config(void)
am335x_gpio_config(GPIO_UART4_TXD);
am335x_gpio_config(GPIO_UART4_RXD);
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
};
#endif
@ -684,7 +672,7 @@ static inline void am335x_uart5config(void)
/* Step 1: Enable power to UART5 */
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
#warning Missing logic
/* Step 2: Enable clocking to UART5 */
@ -694,7 +682,7 @@ static inline void am335x_uart5config(void)
am335x_gpio_config(GPIO_UART5_TXD);
am335x_gpio_config(GPIO_UART5_RXD);
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
};
#endif
@ -1041,18 +1029,18 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg)
case TIOCSBRK: /* BSD compatibility: Turn break on, unconditionally */
{
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
irqstate_t flags = enter_critical_section();
up_enablebreaks(priv, true);
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
}
break;
case TIOCCBRK: /* BSD compatibility: Turn break off, unconditionally */
{
irqstate_t flags;
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
up_enablebreaks(priv, false);
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
}
break;
@ -1216,15 +1204,13 @@ static void up_txint(struct uart_dev_s *dev, bool enable)
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
irqstate_t flags;
flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();
if (enable)
{
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
priv->ier |= UART_IER_THR;
up_serialout(priv, AM335X_UART_IER_OFFSET, priv->ier);
spin_unlock_irqrestore(&priv->spinlock, flags);
/* Fake a TX interrupt here by just calling uart_xmitchars() with
* interrupts disabled (note this may recurse).
*/
@ -1236,9 +1222,9 @@ static void up_txint(struct uart_dev_s *dev, bool enable)
{
priv->ier &= ~UART_IER_THR;
up_serialout(priv, AM335X_UART_IER_OFFSET, priv->ier);
spin_unlock_irqrestore(&priv->spinlock, flags);
}
leave_critical_section(flags);
}
/****************************************************************************

View file

@ -33,7 +33,6 @@
#include <errno.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <imx9_gpiobase.c>
@ -46,10 +45,6 @@
* Private Functions
****************************************************************************/
/* Spinlock */
static spinlock_t g_gpio_lock = SP_UNLOCKED;
/****************************************************************************
* Name: imx9_gpio_dirout
****************************************************************************/
@ -179,7 +174,7 @@ int imx9_config_gpio(gpio_pinset_t pinset)
/* Configure the pin as an input initially to avoid any spurious outputs */
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
/* Configure based upon the pin mode */
@ -228,7 +223,7 @@ int imx9_config_gpio(gpio_pinset_t pinset)
break;
}
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
return ret;
}
@ -248,9 +243,9 @@ void imx9_gpio_write(gpio_pinset_t pinset, bool value)
DEBUGASSERT((unsigned int)port < IMX9_GPIO_NPORTS);
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
imx9_gpio_setoutput(port, pin, value);
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
}
/****************************************************************************
@ -270,7 +265,7 @@ bool imx9_gpio_read(gpio_pinset_t pinset)
DEBUGASSERT((unsigned int)port < IMX9_GPIO_NPORTS);
flags = spin_lock_irqsave(&g_gpio_lock);
flags = enter_critical_section();
if ((pinset & (GPIO_OUTPUT)) == (GPIO_OUTPUT))
{
value = imx9_gpio_get_pinstatus(port, pin);
@ -280,6 +275,6 @@ bool imx9_gpio_read(gpio_pinset_t pinset)
value = imx9_gpio_getinput(port, pin);
}
spin_unlock_irqrestore(&g_gpio_lock, flags);
leave_critical_section(flags);
return value;
}

View file

@ -2438,7 +2438,7 @@ int imx9_i2cbus_uninitialize(struct i2c_master_s *dev)
if (--priv->refs > 0)
{
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
return OK;
}

View file

@ -1798,6 +1798,8 @@ struct spi_dev_s *imx9_lpspibus_initialize(int bus)
{
struct imx9_lpspidev_s *priv = NULL;
irqstate_t flags = enter_critical_section();
#ifdef CONFIG_IMX9_LPSPI1
if (bus == 1)
{
@ -2015,6 +2017,7 @@ struct spi_dev_s *imx9_lpspibus_initialize(int bus)
else
#endif
{
leave_critical_section(flags);
spierr("ERROR: Unsupported SPI bus: %d\n", bus);
return NULL;
}
@ -2058,6 +2061,7 @@ struct spi_dev_s *imx9_lpspibus_initialize(int bus)
}
#endif
leave_critical_section(flags);
return (struct spi_dev_s *)priv;
}

View file

@ -2320,9 +2320,9 @@ static int imx9_epdisable(struct usbdev_ep_s *ep)
/* Cancel any ongoing activity */
imx9_cancelrequests(privep, -ESHUTDOWN);
spin_unlock_irqrestore(&privep->spinlock, flags);
leave_critical_section(flags);
return OK;
}

View file

@ -57,7 +57,6 @@
#include <nuttx/arch.h>
#include <nuttx/clock.h>
#include <nuttx/spinlock.h>
#ifdef CONFIG_SCHED_TICKLESS
@ -91,7 +90,6 @@ static uint32_t g_timer_active;
static irqstate_t g_tmr_sync_count;
static irqstate_t g_tmr_flags;
static spinlock_t g_tmr_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
@ -163,7 +161,7 @@ static inline void up_tmr_sync_up(void)
{
if (!g_tmr_sync_count)
{
g_tmr_flags = spin_lock_irqsave(&g_tmr_lock);
g_tmr_flags = enter_critical_section();
}
g_tmr_sync_count++;
@ -173,7 +171,7 @@ static inline void up_tmr_sync_down(void)
{
if (g_tmr_sync_count == 1)
{
spin_unlock_irqrestore(&g_tmr_lock, g_tmr_flags);
leave_critical_section(g_tmr_flags);
}
if (g_tmr_sync_count > 0)