mirror of
https://github.com/apache/nuttx.git
synced 2026-09-21 21:47:28 +08:00
SMP: Implement enter/leave_critical_section
This commit is contained in:
@@ -40,8 +40,11 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
# include <assert.h>
|
||||
# include <arch/irq.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -97,6 +100,43 @@ extern "C"
|
||||
|
||||
int irq_attach(int irq, xcpt_t isr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: enter_critical_section
|
||||
*
|
||||
* Description:
|
||||
* If SMP is enabled:
|
||||
* Take the CPU IRQ lock and disable interrupts on all CPUs. A thread-
|
||||
* specific counter is increment to indicate that the thread has IRQs
|
||||
* disabled and to support nested calls to enter_critical_section().
|
||||
* If SMP is not enabled:
|
||||
* This function is equivalent to irqsave().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
irqstate_t enter_critical_section(void);
|
||||
#else
|
||||
# define enter_critical_section(f) irqsave(f)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: leave_critical_section
|
||||
*
|
||||
* Description:
|
||||
* If SMP is enabled:
|
||||
* Decrement the IRQ lock count and if it decrements to zero then release
|
||||
* the spinlock.
|
||||
* If SMP is not enabled:
|
||||
* This function is equivalent to irqrestore().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
void leave_critical_section(irqstate_t flags);
|
||||
#else
|
||||
# define leave_critical_section(f) irqrestore(f)
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -560,6 +560,9 @@ struct tcb_s
|
||||
#endif
|
||||
uint16_t flags; /* Misc. general status flags */
|
||||
int16_t lockcount; /* 0=preemptable (not-locked) */
|
||||
#ifdef CONFIG_SMP
|
||||
int16_t irqcount; /* 0=interrupts enabled */
|
||||
#endif
|
||||
|
||||
#if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC)
|
||||
int32_t timeslice; /* RR timeslice OR Sporadic budget */
|
||||
|
||||
@@ -103,7 +103,7 @@ spinlock_t up_testset(volatile FAR spinlock_t *lock);
|
||||
* Name: spin_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize a spinlock object to its initial, unlocked state.
|
||||
* Initialize a non-reentrant spinlock object to its initial, unlocked state.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lock - A reference to the spinlock object to be initialized.
|
||||
@@ -113,7 +113,24 @@ spinlock_t up_testset(volatile FAR spinlock_t *lock);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void spin_initialize(FAR struct spinlock_s *lock);
|
||||
/* void spin_initialize(FAR spinlock_t *lock); */
|
||||
#define spin_initialize(i) do { (l) = SPI_UNLOCKED; } while (0)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: spin_initializer
|
||||
*
|
||||
* Description:
|
||||
* Initialize a re-entrant spinlock object to its initial, unlocked state.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lock - A reference to the spinlock object to be initialized.
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void spin_initializer(FAR struct spinlock_s *lock);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: spin_lock
|
||||
|
||||
Reference in New Issue
Block a user