X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fkern%2Fcoop.c;h=542ed67844a7dc0acddb63196369c68572a50c31;hb=7ce645a0dc4cd3683f854f3aa85a72a86101ddbd;hp=1b2e1bb9bc42497a193d12e736642f8155b67250;hpb=d9d931610bca1df6ceb9227eacc9ff2c7f89b77a;p=bertos.git diff --git a/bertos/kern/coop.c b/bertos/kern/coop.c index 1b2e1bb9..542ed678 100644 --- a/bertos/kern/coop.c +++ b/bertos/kern/coop.c @@ -57,14 +57,42 @@ */ void coop_yield(void); void coop_switch(void); +void coop_wakeup(Process *proc); +/** + * Give the control of the CPU to another process. + * + * \note Assume the current process has been already added to a wait queue. + * + * \warning This should be considered an internal kernel function, even if it + * is allowed, usage from application code is strongly discouraged. + */ void coop_switch(void) { - IRQ_ASSERT_ENABLED(); - ATOMIC(proc_schedule()); } +/** + * Immediately wakeup a process, dispatching it to the CPU. + */ +void coop_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); + current_process = proc; + proc_switchTo(current_process, old_process); + } + else + SCHED_ENQUEUE_HEAD(proc); +} + /** * Co-operative context switch */