Skip to content

Commit 7926baa

Browse files
committed
tuxedo: fix current thread suspend/resume within the same ISR
1 parent 20d90e9 commit 7926baa

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

tuxedo/thread.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,24 @@ MK_NOINLINE void KThreadSwitchTo(KThread* t, PPCIrqState st)
9898

9999
void KThreadResume(KThread* t)
100100
{
101+
KThread* self = KThreadGetSelf();
101102
PPCIrqState st = PPCIrqLockByMsr();
102103

103-
if (!t->suspend || (--t->suspend)) {
104+
if (!t->suspend || (--t->suspend) || t->wait.queue) {
104105
PPCIrqUnlockByMsr(st);
105106
return;
106107
}
107108

108-
if (!t->wait.queue) {
109-
t->state = KTHR_STATE_RUNNING;
109+
t->state = KTHR_STATE_RUNNING;
110+
111+
if (t != self) {
110112
KThreadReschedule(t, st);
111113
} else {
114+
// We are assuming 1) PPCIsInExcpt, 2) KThreadSuspend(self) was called before, and thus 3) __ppc_next_ctx != NULL
115+
if (t->prio < __ppc_next_ctx->prio) {
116+
__ppc_next_ctx = NULL;
117+
}
118+
112119
PPCIrqUnlockByMsr(st);
113120
}
114121
}

0 commit comments

Comments
 (0)