mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
sched/semaphore/spinlock.c: Disable local interrupts in spin_setbit() and spin_clrbit() in order to avoid a deadlock condition.
This commit is contained in:
committed by
Gregory Nutt
parent
d1e234e179
commit
5acd26c88f
@@ -405,8 +405,15 @@ void spin_setbit(FAR volatile cpu_set_t *set, unsigned int cpu,
|
|||||||
#ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
|
||||||
cpu_set_t prev;
|
cpu_set_t prev;
|
||||||
#endif
|
#endif
|
||||||
|
irqstate_t flags;
|
||||||
|
|
||||||
/* First, get the 'setlock' spinlock */
|
/* Disable local interrupts to prevent being re-entered from an interrupt
|
||||||
|
* on the same CPU. This does not effect the behavior on other CPUs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
flags = up_irq_save();
|
||||||
|
|
||||||
|
/* Then, get the 'setlock' spinlock */
|
||||||
|
|
||||||
spin_lock(setlock);
|
spin_lock(setlock);
|
||||||
|
|
||||||
@@ -427,9 +434,10 @@ void spin_setbit(FAR volatile cpu_set_t *set, unsigned int cpu,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Release the 'setlock' */
|
/* Release the 'setlock' and restore local interrupts */
|
||||||
|
|
||||||
spin_unlock(setlock);
|
spin_unlock(setlock);
|
||||||
|
up_irq_restore(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -456,6 +464,13 @@ void spin_clrbit(FAR volatile cpu_set_t *set, unsigned int cpu,
|
|||||||
#ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
|
||||||
cpu_set_t prev;
|
cpu_set_t prev;
|
||||||
#endif
|
#endif
|
||||||
|
irqstate_t flags;
|
||||||
|
|
||||||
|
/* Disable local interrupts to prevent being re-entered from an interrupt
|
||||||
|
* on the same CPU. This does not effect the behavior on other CPUs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
flags = up_irq_save();
|
||||||
|
|
||||||
/* First, get the 'setlock' spinlock */
|
/* First, get the 'setlock' spinlock */
|
||||||
|
|
||||||
@@ -480,9 +495,10 @@ void spin_clrbit(FAR volatile cpu_set_t *set, unsigned int cpu,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Release the 'setlock' */
|
/* Release the 'setlock' and restore local interrupts */
|
||||||
|
|
||||||
spin_unlock(setlock);
|
spin_unlock(setlock);
|
||||||
|
up_irq_restore(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_SPINLOCK */
|
#endif /* CONFIG_SPINLOCK */
|
||||||
|
|||||||
Reference in New Issue
Block a user