From 4d8a776dc196db1ab10bf437799d793b9bbee503 Mon Sep 17 00:00:00 2001 From: sasan-golchin <ahmad.golchin@mail.polimi.it> Date: Tue, 8 Nov 2016 11:17:00 +0100 Subject: [PATCH] Control Scheduler FIX - preemption priority lt; and gt; operators changed to make it possible for not-immediate threads to interrupt each other --- miosix/kernel/scheduler/control/control_scheduler.cpp | 3 ++- .../kernel/scheduler/control/control_scheduler_types.h | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/miosix/kernel/scheduler/control/control_scheduler.cpp b/miosix/kernel/scheduler/control/control_scheduler.cpp index 3de8f97b..a774893f 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()) - nextPreemption = numeric_limits<long long>::max(); + //normally should happen unless an IRQ is set! + nextPreemption = numeric_limits<long long>::max(); else nextPreemption = sleepingList->front()->wakeup_time; timer.IRQsetNextInterrupt(nextPreemption); diff --git a/miosix/kernel/scheduler/control/control_scheduler_types.h b/miosix/kernel/scheduler/control/control_scheduler_types.h index f6860878..3b423156 100755 --- a/miosix/kernel/scheduler/control/control_scheduler_types.h +++ b/miosix/kernel/scheduler/control/control_scheduler_types.h @@ -125,21 +125,23 @@ private: inline bool operator <(ControlSchedulerPriority a, ControlSchedulerPriority b) { - return b.getRealtime() == 1 && a.getRealtime() != 1; + return (b.getRealtime() == 1 && a.getRealtime() != 1) || + (a.getRealtime() != 1 && b.getRealtime() != 1 && a.get() < b.get()); } inline bool operator>(ControlSchedulerPriority a, ControlSchedulerPriority b){ - return a.getRealtime() == 1 && b.getRealtime() != 1; + return (a.getRealtime() == 1 && b.getRealtime() != 1) || + (a.getRealtime() != 1 && b.getRealtime() != 1 && a.get() > b.get()); } inline bool operator ==(ControlSchedulerPriority a, ControlSchedulerPriority b) { - return a.getRealtime() == b.getRealtime(); + return (a.getRealtime() == b.getRealtime()) && (a.get() == b.get()); } inline bool operator !=(ControlSchedulerPriority a, ControlSchedulerPriority b) { - return a.getRealtime() != b.getRealtime(); + return (a.getRealtime() != b.getRealtime()) || (a.get()!= b.get()); } struct ThreadsListItem : public IntrusiveListItem -- GitLab