SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk_strategy_edf.h
Go to the documentation of this file.
1/*
2 * SuperTinyKernel(TM) RTOS: Lightweight High-Performance Deterministic C++ RTOS for Embedded Systems.
3 *
4 * Source: https://github.com/SuperTinyKernel-RTOS
5 *
6 * Copyright (c) 2022-2026 Neutron Code Limited <stk@neutroncode.com>. All Rights Reserved.
7 * License: MIT License, see LICENSE for a full text.
8 */
9
10#ifndef STK_STRATEGY_EDF_H_
11#define STK_STRATEGY_EDF_H_
12
16
17#include "stk_common.h"
18
19namespace stk {
20
61{
62public:
73
77 {}
78
83
92 void AddTask(IKernelTask *task) override
93 {
94 STK_ASSERT(task != nullptr);
95 STK_ASSERT(task->GetHead() == nullptr);
96
97 m_tasks.LinkBack(task);
98 }
99
106 void RemoveTask(IKernelTask *task) override
107 {
108 STK_ASSERT(task != nullptr);
109 STK_ASSERT(GetSize() != 0U);
110 STK_ASSERT((task->GetHead() == &m_tasks) || (task->GetHead() == &m_sleep));
111
112 if (task->GetHead() == &m_tasks)
113 {
114 m_tasks.Unlink(task);
115 }
116 else
117 {
118 m_sleep.Unlink(task);
119 }
120 }
121
139 {
140 IKernelTask *next = nullptr;
141
142 if (!m_tasks.IsEmpty())
143 {
144 IKernelTask *itr = (*m_tasks.GetFirst());
145 IKernelTask *const start = itr;
146
147 next = itr; // initialize earliest found task to the first one
148
149 do
150 {
152 {
153 next = itr;
154 }
155
156 itr = (*itr->GetNext());
157 }
158 while (itr != start);
159 }
160
161 return next;
162 }
163
172 {
173 STK_ASSERT(GetSize() != 0U);
174
175 return (*(!m_tasks.IsEmpty() ? m_tasks.GetFirst() : m_sleep.GetFirst()));
176 }
177
181 size_t GetSize() const override
182 {
183 return m_tasks.GetSize() + m_sleep.GetSize();
184 }
185
192 void OnTaskSleep(IKernelTask *task) override
193 {
194 STK_ASSERT(task != nullptr);
195 STK_ASSERT(task->IsSleeping());
196 STK_ASSERT(task->GetHead() == &m_tasks);
197
198 m_tasks.Unlink(task);
199 m_sleep.LinkBack(task);
200 }
201
210 void OnTaskWake(IKernelTask *task) override
211 {
212 STK_ASSERT(task != nullptr);
213 STK_ASSERT(!task->IsSleeping());
214 STK_ASSERT(task->GetHead() == &m_sleep);
215
216 m_sleep.Unlink(task);
217 m_tasks.LinkBack(task);
218 }
219
220protected:
222
225};
226
227} // namespace stk
228
229#endif /* STK_STRATEGY_EDF_H_ */
Contains interface definitions of the library.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:516
#define STK_VIRT_DTOR
Makes destructors virtual and compliant to strict rules if STK_STRICT_COMPLIANCY=0.
Definition stk_defs.h:261
Namespace of STK package.
Scheduling-strategy-facing interface for a kernel task slot.
Definition stk_common.h:885
virtual Timeout GetHrtRelativeDeadline() const =0
Get HRT task's relative deadline.
DLHeadType ListHeadType
List head type for IKernelTask elements.
Definition stk_common.h:890
virtual bool IsSleeping() const =0
Check whether the task is currently sleeping.
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.
SwitchStrategyEDF()
Construct an empty strategy with no tasks.
IKernelTask * GetFirst() override
Get first task in the managed set (used by the kernel for initial scheduling).
STK_VIRT_DTOR ~SwitchStrategyEDF()=default
Destructor.
IKernelTask::ListHeadType m_sleep
Sleeping (blocked) tasks not eligible for scheduling. Deadline tracking continues in the kernel while...
STK_NONCOPYABLE_CLASS(SwitchStrategyEDF)
EConfig
Compile-time capability flags reported to the kernel.
@ PRIORITY_INHERITANCE_API
This strategy does not require Priority Inheritance and OnTaskPriorityChange() events.
@ DEADLINE_MISSED_API
This strategy does not use OnTaskDeadlineMissed() events.
@ SLEEP_EVENT_API
This strategy requires OnTaskSleep() / OnTaskWake() events to move tasks between the runnable and sle...
@ WEIGHT_API
This strategy does not use per-task weights. Deadline tracking is handled by the kernel in KERNEL_HRT...
size_t GetSize() const override
Get total number of tasks managed by this strategy.
IKernelTask::ListHeadType m_tasks
Runnable tasks eligible for scheduling. Scanned in full by GetNext() each tick to find the minimum re...
void AddTask(IKernelTask *task) override
Add task to the runnable set.
void OnTaskWake(IKernelTask *task) override
Notification that a task has become runnable again.
void OnTaskSleep(IKernelTask *task) override
Notification that a task has entered the sleeping state.
void RemoveTask(IKernelTask *task) override
Remove task from whichever list it currently occupies.
IKernelTask * GetNext() override
Select and return the task with the earliest (minimum) relative deadline.