Changes to thread_wakeup
`thread_wakeup` did not check if target pid is invalid. `thread_wakeup` used `dINT` and `eINT` directly. It should use `disableIRQ` and `restoreIRQ` instead, because there might be other (good) reasons why one might want to call `thread_wakeup` with interrupts disabled. `thread_wakeup` yielded even if the other thread had a lower priority than the current thread.
This commit is contained in:
parent
e536d706e2
commit
791f1cb90f
@ -76,36 +76,24 @@ void thread_sleep()
|
|||||||
int thread_wakeup(int pid)
|
int thread_wakeup(int pid)
|
||||||
{
|
{
|
||||||
DEBUG("thread_wakeup: Trying to wakeup PID %i...\n", pid);
|
DEBUG("thread_wakeup: Trying to wakeup PID %i...\n", pid);
|
||||||
int isr = inISR();
|
|
||||||
|
|
||||||
if (!isr) {
|
int old_state = disableIRQ();
|
||||||
DEBUG("thread_wakeup: Not in interrupt.\n");
|
|
||||||
dINT();
|
|
||||||
}
|
|
||||||
|
|
||||||
int result = sched_threads[pid]->status;
|
tcb_t *other_thread = (tcb_t *) sched_threads[pid];
|
||||||
|
if (other_thread && other_thread->status == STATUS_SLEEPING) {
|
||||||
if (result == STATUS_SLEEPING) {
|
|
||||||
DEBUG("thread_wakeup: Thread is sleeping.\n");
|
DEBUG("thread_wakeup: Thread is sleeping.\n");
|
||||||
sched_set_status((tcb_t *)sched_threads[pid], STATUS_RUNNING);
|
|
||||||
|
|
||||||
if (!isr) {
|
sched_set_status(other_thread, STATUS_RUNNING);
|
||||||
eINT();
|
|
||||||
thread_yield();
|
restoreIRQ(old_state);
|
||||||
}
|
sched_switch(active_thread->priority, other_thread->priority);
|
||||||
else {
|
|
||||||
sched_context_switch_request = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DEBUG("thread_wakeup: Thread is not sleeping!\n");
|
DEBUG("thread_wakeup: Thread is not sleeping!\n");
|
||||||
|
|
||||||
if (!isr) {
|
restoreIRQ(old_state);
|
||||||
eINT();
|
|
||||||
}
|
|
||||||
|
|
||||||
return STATUS_NOT_FOUND;
|
return STATUS_NOT_FOUND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user