X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fkern%2Fpreempt.c;h=1cb5e5a07f88d61f1989888855d3d8425eadb64c;hb=863f8ebdc1af60ca64e0cf4474bfea4b9e6b45b1;hp=f77dd85eff1c632bbd73adf1053b350140cfc1ca;hpb=938512200c9fbd8e08c88dbdddbdc1f030d3b663;p=bertos.git diff --git a/bertos/kern/preempt.c b/bertos/kern/preempt.c index f77dd85e..1cb5e5a0 100644 --- a/bertos/kern/preempt.c +++ b/bertos/kern/preempt.c @@ -121,6 +121,7 @@ void preempt_yield(void); int preempt_needPreempt(void); void preempt_preempt(void); void preempt_switch(void); +void preempt_wakeup(Process *proc); void preempt_init(void); /** @@ -171,11 +172,32 @@ void preempt_preempt(void) void preempt_switch(void) { ASSERT(proc_preemptAllowed()); - IRQ_ASSERT_ENABLED(); ATOMIC(preempt_schedule()); } +/** + * Immediately wakeup a process, dispatching it to the CPU. + */ +void preempt_wakeup(Process *proc) +{ + ASSERT(proc_preemptAllowed()); + ASSERT(current_process); + IRQ_ASSERT_DISABLED(); + + if (prio_proc(proc) >= prio_curr()) + { + Process *old_process = current_process; + + SCHED_ENQUEUE(current_process); + _proc_quantum = CONFIG_KERN_QUANTUM; + current_process = proc; + proc_switchTo(current_process, old_process); + } + else + SCHED_ENQUEUE_HEAD(proc); +} + /** * Voluntarily release the CPU. */