![]() |
SuperTinyKernel™ RTOS 1.06.0
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Monotonic scheduling strategy: Rate-Monotonic (RM) or Deadline-Monotonic (DM), selected at compile time by the _Type template parameter. More...
#include <stk_strategy_monotonic.h>
Public Types | |
| enum | EConfig { WEIGHT_API = 0 , SLEEP_EVENT_API = 0 , DEADLINE_MISSED_API = 0 } |
| Compile-time capability flags reported to the kernel. More... | |
Public Member Functions | |
| SwitchStrategyMonotonic () | |
| Construct an empty strategy with no tasks. | |
| ~SwitchStrategyMonotonic () | |
| Destructor. | |
| void | AddTask (IKernelTask *task) |
| Add a task to the priority-sorted runnable list. | |
| void | RemoveTask (IKernelTask *task) |
| Remove a task from the list. | |
| IKernelTask * | GetNext () |
| Select and return the highest-priority non-sleeping task. | |
| IKernelTask * | GetFirst () const |
| Get the first task in the managed set (used by the kernel for initial scheduling). | |
| size_t | GetSize () const |
| Get the total number of tasks managed by this strategy. | |
| void | OnTaskSleep (IKernelTask *) |
| Not supported, asserts unconditionally. | |
| void | OnTaskWake (IKernelTask *) |
| Not supported, asserts unconditionally. | |
| bool | OnTaskDeadlineMissed (IKernelTask *) |
| Not supported, asserts unconditionally. | |
Private Member Functions | |
| STK_NONCOPYABLE_CLASS (SwitchStrategyMonotonic) | |
Private Attributes | |
| IKernelTask::ListHeadType | m_tasks |
| All tasks (runnable and sleeping) in priority order. GetNext() skips sleeping tasks via IsSleeping(). AddTask() maintains sort order. | |
Monotonic scheduling strategy: Rate-Monotonic (RM) or Deadline-Monotonic (DM), selected at compile time by the _Type template parameter.
| _Type | Policy selector (EMonotonicSwitchStrategyType):
|
m_tasks is maintained as a priority-sorted intrusive list. AddTask() inserts each new task at the correct sorted position (O(n) insertion sort) so that GetNext() need only scan from the front: the first non-sleeping task it encounters is always the highest-priority runnable task. No re-sorting occurs at runtime after a task is added.m_tasks in their sorted position and are skipped by GetNext() via IKernelTask::IsSleeping(). OnTaskSleep() and OnTaskWake() assert unconditionally, the kernel must not be configured to deliver these events to this strategy.KERNEL_HRT mode; using this strategy without KERNEL_HRT produces undefined priority ordering.IKernel::AddTask(periodicity_tc, deadline_tc, ...). Definition at line 69 of file stk_strategy_monotonic.h.
| enum stk::SwitchStrategyMonotonic::EConfig |
Compile-time capability flags reported to the kernel.
| Enumerator | |
|---|---|
| WEIGHT_API | This strategy does not use per-task weights. Priority is derived from HRT timing parameters (GetHrtPeriodicity() for RM, GetHrtDeadline() for DM) at AddTask() time. |
| SLEEP_EVENT_API | This strategy does not use OnTaskSleep() / OnTaskWake() events. Sleeping tasks remain in |
| DEADLINE_MISSED_API | This strategy does not use OnTaskDeadlineMissed() events. |
Definition at line 75 of file stk_strategy_monotonic.h.
|
inlineexplicit |
Construct an empty strategy with no tasks.
Definition at line 84 of file stk_strategy_monotonic.h.
|
inline |
Destructor.
Definition at line 90 of file stk_strategy_monotonic.h.
|
inlinevirtual |
Add a task to the priority-sorted runnable list.
| [in] | task | Task to add. Must not be NULL and must not already be in any list. |
m_tasks so that higher-priority tasks appear closer to the head. The sort key depends on _Type: MSS_TYPE_RATE: key = GetHrtPeriodicity() (smaller -> nearer to head).MSS_TYPE_DEADLINE: key = GetHrtDeadline() (smaller -> nearer to head). Implements stk::ITaskSwitchStrategy.
Definition at line 109 of file stk_strategy_monotonic.h.
|
inlinevirtual |
Get the first task in the managed set (used by the kernel for initial scheduling).
m_tasks (highest priority due to sort order). Asserts if m_tasks is empty. m_tasks there is no sleep-list fallback path, unlike RR, SWRR, EDF, and FP strategies. The returned task may be sleeping; the kernel uses it only to seed the initial context before the first GetNext() call. Implements stk::ITaskSwitchStrategy.
Definition at line 217 of file stk_strategy_monotonic.h.
|
inlinevirtual |
Select and return the highest-priority non-sleeping task.
m_tasks, or NULL if every task in the list is currently sleeping (kernel will sleep until the next activation). m_tasks is sorted in descending priority order by AddTask(), a linear scan from the head is sufficient: the first task for which IsSleeping() returns false is always the highest-priority runnable task. Complexity is O(k) where k is the number of sleeping tasks at the front of the list (i.e. higher-priority tasks currently between activations). m_tasks is empty; at least one task must be registered before GetNext() is called. Implements stk::ITaskSwitchStrategy.
Definition at line 186 of file stk_strategy_monotonic.h.
|
inlinevirtual |
Get the total number of tasks managed by this strategy.
m_tasks. Includes both runnable and sleeping tasks since this strategy does not maintain a separate sleep list. Implements stk::ITaskSwitchStrategy.
Definition at line 228 of file stk_strategy_monotonic.h.
Referenced by stk::SwitchStrategyMonotonic< MSS_TYPE_RATE >::RemoveTask().
|
inlinevirtual |
Not supported, asserts unconditionally.
Implements stk::ITaskSwitchStrategy.
Definition at line 256 of file stk_strategy_monotonic.h.
|
inlinevirtual |
Not supported, asserts unconditionally.
m_tasks in their sorted position and are detected by IsSleeping() in GetNext(). Calling this method indicates a kernel/strategy configuration mismatch. Implements stk::ITaskSwitchStrategy.
Definition at line 238 of file stk_strategy_monotonic.h.
|
inlinevirtual |
Not supported, asserts unconditionally.
Implements stk::ITaskSwitchStrategy.
Definition at line 247 of file stk_strategy_monotonic.h.
|
inlinevirtual |
Remove a task from the list.
| [in] | task | Task to remove. Must not be NULL. Must be in m_tasks (asserted). |
m_tasks, so this method simply unlinks the task unconditionally without a list-membership check. Implements stk::ITaskSwitchStrategy.
Definition at line 166 of file stk_strategy_monotonic.h.
|
private |
|
private |
All tasks (runnable and sleeping) in priority order. GetNext() skips sleeping tasks via IsSleeping(). AddTask() maintains sort order.
Definition at line 266 of file stk_strategy_monotonic.h.