mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 13:52:22 +08:00
boards/boardctl.c: use spinlock IRQ-safe interfaces for consistency
Replace direct up_irq_save/up_irq_restore calls with spinlock IRQ-safe interfaces (spin_lock_irqsave, spin_trylock_irqsave, spin_unlock_irqrestore) to maintain semantic consistency when both spinlock and IRQ flags are used together. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
+30
-25
@@ -804,42 +804,47 @@ int boardctl(unsigned int cmd, uintptr_t arg)
|
||||
|
||||
if (spinlock->action == BOARDIOC_SPINLOCK_LOCK)
|
||||
{
|
||||
if (flags != NULL)
|
||||
{
|
||||
*flags = up_irq_save();
|
||||
}
|
||||
|
||||
if (lock != NULL)
|
||||
{
|
||||
spin_lock(lock);
|
||||
if (flags != NULL)
|
||||
{
|
||||
*flags = spin_lock_irqsave(lock);
|
||||
}
|
||||
else
|
||||
{
|
||||
spin_lock(lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (spinlock->action == BOARDIOC_SPINLOCK_TRYLOCK)
|
||||
{
|
||||
if (flags != NULL)
|
||||
{
|
||||
*flags = up_irq_save();
|
||||
}
|
||||
|
||||
if (!spin_trylock(lock))
|
||||
{
|
||||
ret = -EBUSY;
|
||||
if (flags != NULL)
|
||||
{
|
||||
up_irq_restore(*flags);
|
||||
}
|
||||
}
|
||||
if (lock != NULL)
|
||||
{
|
||||
if (flags != NULL)
|
||||
{
|
||||
if (!spin_trylock_irqsave(lock, *flags))
|
||||
{
|
||||
ret = -EBUSY;
|
||||
}
|
||||
}
|
||||
else if (!spin_trylock(lock))
|
||||
{
|
||||
ret = -EBUSY;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (spinlock->action == BOARDIOC_SPINLOCK_UNLOCK)
|
||||
{
|
||||
if (flags != NULL)
|
||||
{
|
||||
up_irq_restore(*flags);
|
||||
}
|
||||
|
||||
if (lock != NULL)
|
||||
{
|
||||
spin_unlock(lock);
|
||||
if (flags != NULL)
|
||||
{
|
||||
spin_unlock_irqrestore(lock, *flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
spin_unlock(lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user