Skip to content

Commit

Permalink
spinlock: rm g_irq_spin and g_irq_spin_count
Browse files Browse the repository at this point in the history
Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Dec 24, 2024
1 parent 4060180 commit 6c72a8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 67 deletions.
68 changes: 9 additions & 59 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 @@ -451,21 +443,8 @@ 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);
}

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

return ret;
}
Expand All @@ -478,14 +457,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 +468,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 +588,8 @@ 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);
}
DEBUGASSERT(lock);
spin_unlock_wo_note(lock);

up_irq_restore(flags);
}
Expand All @@ -645,21 +602,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

0 comments on commit 6c72a8f

Please sign in to comment.