diff --git a/miosix/kernel/scheduler/control/control_scheduler.cpp b/miosix/kernel/scheduler/control/control_scheduler.cpp index a774893f404c3581610776ea79e700de2d9f047d..8952dc4f7100d4891a5c5c2d29e735cadc982371 100644 --- a/miosix/kernel/scheduler/control/control_scheduler.cpp +++ b/miosix/kernel/scheduler/control/control_scheduler.cpp @@ -200,7 +200,8 @@ long long ControlScheduler::IRQgetNextPreemption() // Should be called when the current thread is the idle thread static inline void IRQsetNextPreemptionForIdle(){ if (sleepingList->empty()) - //normally should happen unless an IRQ is set! + //normally should not happen unless an IRQ is already set and able to + //preempt idle thread nextPreemption = numeric_limits<long long>::max(); else nextPreemption = sleepingList->front()->wakeup_time; diff --git a/miosix/kernel/scheduler/control/control_scheduler_types.h b/miosix/kernel/scheduler/control/control_scheduler_types.h index 3b4231563a9c8741f3e7922ef0d678fe9280b30e..bcf35f9975c0a945cbdccc154319461ad2b9dd16 100755 --- a/miosix/kernel/scheduler/control/control_scheduler_types.h +++ b/miosix/kernel/scheduler/control/control_scheduler_types.h @@ -125,13 +125,15 @@ private: inline bool operator <(ControlSchedulerPriority a, ControlSchedulerPriority b) { - return (b.getRealtime() == 1 && a.getRealtime() != 1) || - (a.getRealtime() != 1 && b.getRealtime() != 1 && a.get() < b.get()); + //rule 1) Idle thread should be always preempted by any thread! + //rule 2) Only REALTIME_PRIORITY_IMMEDIATE threads can preempt other threads + //right away, for other real-time priorities, the scheduler does not + //require to be called before the end of the current burst! + return a.get()==-1 || (a.getRealtime() != 1 && b.getRealtime() == 1); } inline bool operator>(ControlSchedulerPriority a, ControlSchedulerPriority b){ - return (a.getRealtime() == 1 && b.getRealtime() != 1) || - (a.getRealtime() != 1 && b.getRealtime() != 1 && a.get() > b.get()); + return b.get()==-1 || (a.getRealtime() == 1 && b.getRealtime() != 1); } inline bool operator ==(ControlSchedulerPriority a, ControlSchedulerPriority b)