Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sched: remove spin_lock_irqsave(NULL) support #15324

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arch/arm/src/rp2040/rp2040_pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
#define hw_claim_lock() spin_lock_irqsave(&pio_lock)
#define hw_claim_unlock(save) spin_unlock_irqrestore(&pio_lock, save)
#else
#define hw_claim_lock() spin_lock_irqsave(NULL)
#define hw_claim_unlock(save) spin_unlock_irqrestore(NULL, save)
#define hw_claim_lock() up_irq_save()
#define hw_claim_unlock(save) up_irq_restore(save)
#endif

/****************************************************************************
Expand Down
72 changes: 10 additions & 62 deletions include/nuttx/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ void sched_note_spinlock_unlock(FAR volatile spinlock_t *spinlock);
* Public Data Types
****************************************************************************/

/* Used for access control */

extern volatile spinlock_t g_irq_spin;

/* Handles nested calls to spin_lock_irqsave and spin_unlock_irqrestore */

extern volatile uint8_t g_irq_spin_count[CONFIG_SMP_NCPUS];

/****************************************************************************
* Name: up_testset
*
Expand Down Expand Up @@ -448,26 +440,12 @@ static inline_function void spin_unlock(FAR volatile spinlock_t *lock)
static inline_function
irqstate_t spin_lock_irqsave_wo_note(FAR volatile spinlock_t *lock)
{
irqstate_t ret;
ret = up_irq_save();

if (NULL == lock)
{
int me = this_cpu();
if (0 == g_irq_spin_count[me])
{
spin_lock_wo_note(&g_irq_spin);
}
irqstate_t flags;
flags = up_irq_save();

g_irq_spin_count[me]++;
DEBUGASSERT(0 != g_irq_spin_count[me]);
}
else
{
spin_lock_wo_note(lock);
}
spin_lock_wo_note(lock);

return ret;
return flags;
}
#else
# define spin_lock_irqsave_wo_note(l) ((void)(l), up_irq_save())
Expand All @@ -478,14 +456,7 @@ irqstate_t spin_lock_irqsave_wo_note(FAR volatile spinlock_t *lock)
*
* Description:
* If SMP is enabled:
* If the argument lock is not specified (i.e. NULL),
* disable local interrupts and take the global spinlock (g_irq_spin)
* if the call counter (g_irq_spin_count[cpu]) equals to 0. Then the
* counter on the CPU is incremented to allow nested calls and return
* the interrupt state.
*
* If the argument lock is specified,
* disable local interrupts and take the lock spinlock and return
* Disable local interrupts and take the lock spinlock and return
* the interrupt state.
*
* NOTE: This API is very simple to protect data (e.g. H/W register
Expand All @@ -496,9 +467,7 @@ irqstate_t spin_lock_irqsave_wo_note(FAR volatile spinlock_t *lock)
* This function is equivalent to up_irq_save().
*
* Input Parameters:
* lock - Caller specific spinlock. If specified NULL, g_irq_spin is used
* and can be nested. Otherwise, nested call for the same lock
* would cause a deadlock
* lock - Caller specific spinlock. not NULL.
*
* Returned Value:
* An opaque, architecture-specific value that represents the state of
Expand Down Expand Up @@ -618,21 +587,7 @@ static inline_function
void spin_unlock_irqrestore_wo_note(FAR volatile spinlock_t *lock,
irqstate_t flags)
{
if (NULL == lock)
{
int me = this_cpu();
DEBUGASSERT(0 < g_irq_spin_count[me]);
g_irq_spin_count[me]--;

if (0 == g_irq_spin_count[me])
{
spin_unlock_wo_note(&g_irq_spin);
}
}
else
{
spin_unlock_wo_note(lock);
}
spin_unlock_wo_note(lock);

up_irq_restore(flags);
}
Expand All @@ -645,21 +600,14 @@ void spin_unlock_irqrestore_wo_note(FAR volatile spinlock_t *lock,
*
* Description:
* If SMP is enabled:
* If the argument lock is not specified (i.e. NULL),
* decrement the call counter (g_irq_spin_count[cpu]) and if it
* decrements to zero then release the spinlock (g_irq_spin) and
* restore the interrupt state as it was prior to the previous call to
* spin_lock_irqsave(NULL).
*
* If the argument lock is specified, release the lock and
* restore the interrupt state as it was prior to the previous call to
* spin_lock_irqsave(lock).
* Release the lock and restore the interrupt state as it was prior
* to the previous call to spin_lock_irqsave(lock).
*
* If SMP is not enabled:
* This function is equivalent to up_irq_restore().
*
* Input Parameters:
* lock - Caller specific spinlock. If specified NULL, g_irq_spin is used.
* lock - Caller specific spinlock. not NULL
*
* flags - The architecture-specific value that represents the state of
* the interrupts prior to the call to spin_lock_irqsave(lock);
Expand Down
8 changes: 0 additions & 8 deletions sched/irq/irq_spinlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@
* Public Data
****************************************************************************/

/* Used for access control */

volatile spinlock_t g_irq_spin = SP_UNLOCKED;

/* Handles nested calls to spin_lock_irqsave and spin_unlock_irqrestore */

volatile uint8_t g_irq_spin_count[CONFIG_SMP_NCPUS];

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down
Loading