diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 4c7d6814542..dabd07cbc80 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -69,10 +69,12 @@ void sched_unlock(void) * then pre-emption has been re-enabled. */ - if (rtcb != NULL && --rtcb->lockcount == 0) + if (rtcb != NULL && rtcb->lockcount == 1) { irqstate_t flags = enter_critical_section_wo_note(); + rtcb->lockcount = 0; + /* Note that we no longer have pre-emption disabled. */ nxsched_critmon_preemption(rtcb, false, return_address(0)); @@ -164,5 +166,9 @@ void sched_unlock(void) leave_critical_section_wo_note(flags); } + else + { + rtcb->lockcount--; + } } }