diff --git a/sched/addrenv/addrenv.c b/sched/addrenv/addrenv.c index 64c3d2b37b8..a3a0d93ad40 100644 --- a/sched/addrenv/addrenv.c +++ b/sched/addrenv/addrenv.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -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); } /****************************************************************************