AX25: refactor in order to add the possibility to specify a path for
[bertos.git] / bertos / kern / preempt.c
index f77dd85eff1c632bbd73adf1053b350140cfc1ca..4b5e66c3d2261b67874b645c79e0351f7e8d1805 100644 (file)
@@ -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);
 
 /**
@@ -141,6 +142,8 @@ int preempt_needPreempt(void)
                return 0;
        if (!proc_preemptAllowed())
                return 0;
+       if (LIST_EMPTY(&proc_ready_list))
+               return 0;
        return _proc_quantum ? prio_next() > prio_curr() :
                        prio_next() >= prio_curr();
 }
@@ -171,11 +174,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.
  */