SuperTinyKernel™ RTOS 1.05.3
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:
72
76 {}
77
83
92 void AddTask(IKernelTask *task)
93 {
94 STK_ASSERT(task != nullptr);
95 STK_ASSERT(task->GetHead() == nullptr);
96
97 m_tasks.LinkBack(task);
98 }
99
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 m_tasks.Unlink(task);
114 else
115 m_sleep.Unlink(task);
116 }
117
135 {
136 if (m_tasks.IsEmpty())
137 return nullptr; // idle
138
139 IKernelTask *itr = (*m_tasks.GetFirst()), * const start = itr;
140 IKernelTask *earliest = itr;
141
142 do
143 {
144 if (itr->GetHrtRelativeDeadline() < earliest->GetHrtRelativeDeadline())
145 earliest = itr;
146 }
147 while ((itr = (*itr->GetNext())) != start);
148
149 return earliest;
150 }
151
160 {
161 STK_ASSERT(GetSize() != 0U);
162
163 if (!m_tasks.IsEmpty())
164 return (*m_tasks.GetFirst());
165 else
166 return (*m_sleep.GetFirst());
167 }
168
172 size_t GetSize() const
173 {
174 return m_tasks.GetSize() + m_sleep.GetSize();
175 }
176
184 {
185 STK_ASSERT(task != nullptr);
186 STK_ASSERT(task->IsSleeping());
187 STK_ASSERT(task->GetHead() == &m_tasks);
188
189 m_tasks.Unlink(task);
190 m_sleep.LinkBack(task);
191 }
192
202 {
203 STK_ASSERT(task != nullptr);
204 STK_ASSERT(!task->IsSleeping());
205 STK_ASSERT(task->GetHead() == &m_sleep);
206
207 m_sleep.Unlink(task);
208 m_tasks.LinkBack(task);
209 }
210
215 {
216 // Budget Overrun API unsupported
217 STK_ASSERT(false);
218 return false;
219 }
220
221protected:
223
226};
227
228} // namespace stk
229
230#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:330
Namespace of STK package.
Scheduling-strategy-facing interface for a kernel task slot.
Definition stk_common.h:493
virtual Timeout GetHrtRelativeDeadline() const =0
Get HRT task's relative deadline.
DLHeadType ListHeadType
List head type for IKernelTask elements.
Definition stk_common.h:498
virtual bool IsSleeping() const =0
Check whether the task is currently sleeping.
Interface for a task switching strategy implementation.
Definition stk_common.h:782
DLHeadType * GetHead() const
Get the list head this entry currently belongs to.
DLEntryType * GetNext() const
Get the next entry in the list.
SwitchStrategyEDF()
Construct an empty strategy with no tasks.
bool OnTaskDeadlineMissed(IKernelTask *)
Not supported, asserts unconditionally.
size_t GetSize() const
Get total number of tasks managed by this strategy.
void OnTaskSleep(IKernelTask *task)
Notification that a task has entered the sleeping state.
~SwitchStrategyEDF()
Destructor.
IKernelTask * GetFirst() const
Get first task in the managed set (used by the kernel for initial scheduling).
IKernelTask * GetNext()
Select and return the task with the earliest (minimum) relative deadline.
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.
@ 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...
void OnTaskWake(IKernelTask *task)
Notification that a task has become runnable again.
void AddTask(IKernelTask *task)
Add task to the runnable set.
IKernelTask::ListHeadType m_tasks
Runnable tasks eligible for scheduling. Scanned in full by GetNext() each tick to find the minimum re...
void RemoveTask(IKernelTask *task)
Remove task from whichever list it currently occupies.