mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 07:12:54 +08:00
addrenv/addrenv.c: Use atomic_ functions to handle the reference counter
The performance penalty in SMP mode is too big for taking the big kernel lock simply to bump the address environment reference counter; fix this by using the compiler provided atomic macros.
This commit is contained in:
+3
-11
@@ -30,6 +30,7 @@
|
|||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include <nuttx/addrenv.h>
|
#include <nuttx/addrenv.h>
|
||||||
|
#include <nuttx/atomic.h>
|
||||||
#include <nuttx/irq.h>
|
#include <nuttx/irq.h>
|
||||||
#include <nuttx/sched.h>
|
#include <nuttx/sched.h>
|
||||||
#include <nuttx/wqueue.h>
|
#include <nuttx/wqueue.h>
|
||||||
@@ -400,9 +401,7 @@ int addrenv_restore(FAR struct addrenv_s *addrenv)
|
|||||||
|
|
||||||
void addrenv_take(FAR struct addrenv_s *addrenv)
|
void addrenv_take(FAR struct addrenv_s *addrenv)
|
||||||
{
|
{
|
||||||
irqstate_t flags = enter_critical_section();
|
atomic_fetch_add(&addrenv->refs, 1);
|
||||||
addrenv->refs++;
|
|
||||||
leave_critical_section(flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -422,14 +421,7 @@ void addrenv_take(FAR struct addrenv_s *addrenv)
|
|||||||
|
|
||||||
int addrenv_give(FAR struct addrenv_s *addrenv)
|
int addrenv_give(FAR struct addrenv_s *addrenv)
|
||||||
{
|
{
|
||||||
irqstate_t flags;
|
return atomic_fetch_sub(&addrenv->refs, 1);
|
||||||
int refs;
|
|
||||||
|
|
||||||
flags = enter_critical_section();
|
|
||||||
refs = --addrenv->refs;
|
|
||||||
leave_critical_section(flags);
|
|
||||||
|
|
||||||
return refs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user