sched: Remove race condition in sched_unlock
When exiting schedlock, that task should first take the critical section and only after that decrease the lockcount to 0. Otherwise an interrupt might cause a re-schedule before the task enters the critical section, which makes the following code meaningless. Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
This commit is contained in:
parent
3ba6047e29
commit
f55e6f6383
1 changed files with 7 additions and 1 deletions
|
|
@ -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--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue