This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new e2616e7866 addrenv/addrenv.c: Use atomic_ functions to handle the
reference counter
e2616e7866 is described below
commit e2616e7866ace4c2ce4cd16161c7f7e450d07ac6
Author: Ville Juven <[email protected]>
AuthorDate: Thu Nov 14 15:35:48 2024 +0200
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.
---
sched/addrenv/addrenv.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/sched/addrenv/addrenv.c b/sched/addrenv/addrenv.c
index 64c3d2b37b..a3a0d93ad4 100644
--- a/sched/addrenv/addrenv.c
+++ b/sched/addrenv/addrenv.c
@@ -30,6 +30,7 @@
#include <debug.h>
#include <nuttx/addrenv.h>
+#include <nuttx/atomic.h>
#include <nuttx/irq.h>
#include <nuttx/sched.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)
{
- irqstate_t flags = enter_critical_section();
- addrenv->refs++;
- leave_critical_section(flags);
+ atomic_fetch_add(&addrenv->refs, 1);
}
/****************************************************************************
@@ -422,14 +421,7 @@ void addrenv_take(FAR struct addrenv_s *addrenv)
int addrenv_give(FAR struct addrenv_s *addrenv)
{
- irqstate_t flags;
- int refs;
-
- flags = enter_critical_section();
- refs = --addrenv->refs;
- leave_critical_section(flags);
-
- return refs;
+ return atomic_fetch_sub(&addrenv->refs, 1);
}
/****************************************************************************