10#ifndef STK_STRATEGY_SWRROBIN_H_
11#define STK_STRATEGY_SWRROBIN_H_
149 int32_t max_weight = INT32_MIN;
156 if (candidate_weight > max_weight)
158 max_weight = candidate_weight;
164 while (itr != start);
Contains interface definitions of the library.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
#define STK_VIRT_DTOR
Makes destructors virtual and compliant to strict rules if STK_STRICT_COMPLIANCY=0.
Namespace of STK package.
static constexpr Weight NO_WEIGHT
Weight value: weight is not set.
SwitchStrategySmoothWeightedRoundRobin SwitchStrategySWRR
Shorthand alias for SwitchStrategySmoothWeightedRoundRobin.
Scheduling-strategy-facing interface for a kernel task slot.
virtual Weight GetCurrentWeight() const =0
Get the current dynamic weight value of this task.
virtual Weight GetWeight() const =0
Get static base weight assigned to the task.
DLHeadType ListHeadType
List head type for IKernelTask elements.
virtual bool IsSleeping() const =0
Check whether the task is currently sleeping.
virtual void SetCurrentWeight(Weight weight)=0
Set the current dynamic weight value used by the scheduling strategy.
Interface for a task switching strategy implementation.
DLEntryType * GetNext()
Get the next entry in the list.
DLHeadType * GetHead()
Get the list head this entry currently belongs to.
Smooth Weighted Round-Robin (SWRR) task-switching strategy: distributes CPU time proportionally to pe...
STK_VIRT_DTOR ~SwitchStrategySmoothWeightedRoundRobin()=default
Destructor.
IKernelTask * GetFirst() override
Get first task in the managed set (used by the kernel for initial scheduling).
STK_NONCOPYABLE_CLASS(SwitchStrategySmoothWeightedRoundRobin)
void RemoveTask(IKernelTask *task) override
Remove task from whichever list it currently occupies.
SwitchStrategySmoothWeightedRoundRobin()
Construct an empty strategy with no tasks and a zero total weight.
void OnTaskWake(IKernelTask *task) override
Notification that a task has become runnable again.
void AddActive(IKernelTask *task)
Append task to m_tasks and update the total weight.
int32_t m_total_weight
Sum of static weights (GetWeight()) of all tasks currently in m_tasks. Sleeping tasks are excluded....
void OnTaskSleep(IKernelTask *task) override
Notification that a task has entered the sleeping state.
EConfig
Compile-time capability flags reported to the kernel.
@ PRIORITY_INHERITANCE_API
This strategy does not require Priority Inheritance and OnTaskPriorityChange() events.
@ SLEEP_EVENT_API
This strategy requires OnTaskSleep() / OnTaskWake() events to keep m_total_weight accurate as tasks m...
@ DEADLINE_MISSED_API
This strategy does not use OnTaskDeadlineMissed() events.
@ WEIGHT_API
This strategy uses per-task static and dynamic weights; the kernel must expose the Weight API on each...
IKernelTask * GetNext() override
Select and return the next task to run, applying one step of the SWRR algorithm.
void RemoveActive(IKernelTask *task)
Remove task from m_tasks and update the total weight.
size_t GetSize() const override
Get the total number of tasks managed by this strategy.
void AddTask(IKernelTask *task) override
Add task to the runnable set.
IKernelTask::ListHeadType m_tasks
Runnable tasks eligible for scheduling.
IKernelTask::ListHeadType m_sleep
Sleeping (blocked) tasks not eligible for scheduling.