1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

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:
René Kijewski 2014-02-13 23:17:36 +01:00
parent e536d706e2
commit 791f1cb90f

View File

@ -76,36 +76,24 @@ void thread_sleep()
int thread_wakeup(int pid)
{
DEBUG("thread_wakeup: Trying to wakeup PID %i...\n", pid);
int isr = inISR();
if (!isr) {
DEBUG("thread_wakeup: Not in interrupt.\n");
dINT();
}
int old_state = disableIRQ();
int result = sched_threads[pid]->status;
if (result == STATUS_SLEEPING) {
tcb_t *other_thread = (tcb_t *) sched_threads[pid];
if (other_thread && other_thread->status == STATUS_SLEEPING) {
DEBUG("thread_wakeup: Thread is sleeping.\n");
sched_set_status((tcb_t *)sched_threads[pid], STATUS_RUNNING);
if (!isr) {
eINT();
thread_yield();
}
else {
sched_context_switch_request = 1;
}
sched_set_status(other_thread, STATUS_RUNNING);
restoreIRQ(old_state);
sched_switch(active_thread->priority, other_thread->priority);
return 1;
}
else {
DEBUG("thread_wakeup: Thread is not sleeping!\n");
if (!isr) {
eINT();
}
restoreIRQ(old_state);
return STATUS_NOT_FOUND;
}
}