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:
parent
8714154338
commit
e6339eac1a
1 changed files with 6 additions and 1 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include <pm/pm.h>
|
#include <pm/pm.h>
|
||||||
#include <pm/policy.h>
|
#include <pm/policy.h>
|
||||||
#include <sys_clock.h>
|
#include <sys_clock.h>
|
||||||
|
#include <sys/__assert.h>
|
||||||
#include <sys/time_units.h>
|
#include <sys/time_units.h>
|
||||||
#include <sys/atomic.h>
|
#include <sys/atomic.h>
|
||||||
#include <toolchain.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)
|
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)
|
bool pm_policy_state_lock_is_active(enum pm_state state)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue