pm: policy: assert on unbalanced state lock get/put

The state lock get/put calls should always be balanced: first call get
and then put. Add an assertion in case lock counter is about to go
negative, indicating a programming error.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-01-20 23:01:37 +01:00 committed by Carles Cufí
commit e6339eac1a

View file

@ -8,6 +8,7 @@
#include <pm/pm.h>
#include <pm/policy.h>
#include <sys_clock.h>
#include <sys/__assert.h>
#include <sys/time_units.h>
#include <sys/atomic.h>
#include <toolchain.h>
@ -51,7 +52,11 @@ void pm_policy_state_lock_get(enum pm_state state)
void pm_policy_state_lock_put(enum pm_state state)
{
atomic_dec(&state_lock_cnt[state]);
atomic_t cnt = atomic_dec(&state_lock_cnt[state]);
ARG_UNUSED(cnt);
__ASSERT(cnt >= 1, "Unbalanced state lock get/put");
}
bool pm_policy_state_lock_is_active(enum pm_state state)