Merge pull request #698 from Kijewski/thread_wakeup-dint

Changes to `thread_wakeup`
This commit is contained in:
Kaspar Schleiser 2014-03-03 18:17:18 +01:00
commit 402fae5bbe

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;
}
}