mirror of
https://github.com/apache/nuttx.git
synced 2026-05-19 20:06:24 +08:00
sched/addrenv: replace critical section with spinlock for refs protection
Build Documentation / build-html (push) Has been cancelled
Build Documentation / build-html (push) Has been cancelled
Replace global enter_critical_section() calls with lightweight spinlock in addrenv_switch() to reduce interrupt latency, and convert refs counter to atomic_t for thread-safe reference counting without blocking operations. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/atomic.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
|
||||
#include <arch/arch.h>
|
||||
@@ -264,7 +265,7 @@ struct addrenv_s
|
||||
{
|
||||
struct arch_addrenv_s addrenv; /* The address environment page directory */
|
||||
struct work_s work; /* Worker to free address environment */
|
||||
int refs; /* Users of address environment */
|
||||
atomic_t refs; /* Users of address environment */
|
||||
};
|
||||
|
||||
typedef struct addrenv_s addrenv_t;
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
*/
|
||||
|
||||
static FAR struct addrenv_s *g_addrenv[CONFIG_SMP_NCPUS];
|
||||
static spinlock_t g_addrenv_lock = SP_UNLOCKED;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
@@ -142,7 +143,7 @@ int addrenv_switch(FAR struct tcb_s *tcb)
|
||||
return OK;
|
||||
}
|
||||
|
||||
flags = enter_critical_section();
|
||||
flags = spin_lock_irqsave_nopreempt(&g_addrenv_lock);
|
||||
|
||||
cpu = this_cpu();
|
||||
curr = g_addrenv[cpu];
|
||||
@@ -190,7 +191,7 @@ int addrenv_switch(FAR struct tcb_s *tcb)
|
||||
g_addrenv[cpu] = next;
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
spin_unlock_irqrestore_nopreempt(&g_addrenv_lock, flags);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -217,7 +218,7 @@ FAR struct addrenv_s *addrenv_allocate(void)
|
||||
{
|
||||
/* Take reference so this won't get freed */
|
||||
|
||||
addrenv->refs = 1;
|
||||
atomic_set(&addrenv->refs, 1);
|
||||
}
|
||||
|
||||
return addrenv;
|
||||
|
||||
Reference in New Issue
Block a user