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::ITaskSwitchStrategy Class Referenceabstract

Interface for a task switching strategy implementation. More...

#include <stk_common.h>

Inheritance diagram for stk::ITaskSwitchStrategy:

Public Member Functions

virtual void AddTask (IKernelTask *task)=0
 Add task.
virtual void RemoveTask (IKernelTask *task)=0
 Remove task.
virtual IKernelTaskGetFirst () const =0
 Get first task.
virtual IKernelTaskGetNext ()=0
 Advance the internal iterator and return the next runnable task.
virtual size_t GetSize () const =0
 Get number of tasks currently managed by this strategy.
virtual void OnTaskSleep (IKernelTask *task)=0
 Notification that a task has entered sleep/blocked state.
virtual void OnTaskWake (IKernelTask *task)=0
 Notification that a task is becoming runnable again.
virtual bool OnTaskDeadlineMissed (IKernelTask *task)=0
 Notification that a task has exceeded its HRT deadline; returns whether the strategy can recover without a hard fault.

Detailed Description

Interface for a task switching strategy implementation.

Note
Combines the Strategy and Iterator design patterns.
  • Strategy: concrete subclasses encapsulate the scheduling policy (round-robin, EDF, rate-monotonic, weighted round-robin, etc.) independently of the kernel.
  • Iterator: GetFirst() and GetNext() expose a stateful forward-iterator over the runnable task set. The cursor is owned by the concrete implementation and is not exposed directly, iteration is therefore not re-entrant.

Implementation must declare the following compile-time constants for reporting its capabilities to the kernel (place inside EConfig enum):

Example:

enum EConfig
{
WEIGHT_API = 0, // (1) if strategy needs Weight API of the kernel task, (0) otherwise (see \a IKernelTask and Weight API functions)
SLEEP_EVENT_API = 0, // (1) if strategy needs Sleep API events generated by the kernel, (0) otherwise (see \a ITaskSwitchStrategy::OnTaskSleep, \a ITaskSwitchStrategy::OnTaskWake)
DEADLINE_MISSED_API = 0 // (1) if strategy implements OnTaskDeadlineMissed() and can absorb HRT deadline overruns, (0) otherwise (see \a ITaskSwitchStrategy::OnTaskDeadlineMissed)
};

Definition at line 781 of file stk_common.h.

Member Function Documentation

◆ AddTask()

◆ GetFirst()

◆ GetNext()

virtual IKernelTask * stk::ITaskSwitchStrategy::GetNext ( )
pure virtual

Advance the internal iterator and return the next runnable task.

Returns
Pointer to the next active task to schedule, or NULL if no runnable tasks are available (in which case the kernel transitions to FSM_STATE_SLEEPING).
Note
Implementations maintain an internal cursor. This method is not re-entrant, concurrent calls from multiple contexts are not supported.

Implemented in stk::SwitchStrategyEDF, stk::SwitchStrategyFixedPriority< MAX_PRIORITIES >, stk::SwitchStrategyFixedPriority< 32 >, stk::SwitchStrategyMonotonic< _Type >, stk::SwitchStrategyMonotonic< MSS_TYPE_DEADLINE >, stk::SwitchStrategyMonotonic< MSS_TYPE_RATE >, stk::SwitchStrategyRoundRobin, and stk::SwitchStrategySmoothWeightedRoundRobin.

Referenced by stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TestAlgorithm(), and stk::test::TestPriorityNext().

Here is the caller graph for this function:

◆ GetSize()

◆ OnTaskDeadlineMissed()

virtual bool stk::ITaskSwitchStrategy::OnTaskDeadlineMissed ( IKernelTask * task)
pure virtual

Notification that a task has exceeded its HRT deadline; returns whether the strategy can recover without a hard fault.

Parameters
[in]taskThe task whose deadline was missed. Must not be nullptr.
Returns
true — the strategy has absorbed the overrun (e.g. by escalating its scheduling mode); the kernel must not call HrtHardFailDeadline() for this tick. false — the strategy cannot recover; the kernel must call HrtHardFailDeadline() as normal.
Note
Budget Overrun API. Called by the kernel from UpdateTaskState() within a tick, after GetNext() has already been called for that tick. Only invoked when DEADLINE_MISSED_API == 1 in the concrete strategy's EConfig. Strategies that set DEADLINE_MISSED_API = 0 do not need to implement this method; the kernel will not call it and will proceed directly to HrtHardFailDeadline().
Returning true carries no implicit side-effects on task sleep state or duration counters — normal tick-driven scheduling remains responsible for those. This call only communicates "do not hard-fault this tick."
The base implementation returns false (unrecoverable), which is the correct default for strategies that do not implement overrun recovery.

Implemented in stk::SwitchStrategyEDF, stk::SwitchStrategyFixedPriority< MAX_PRIORITIES >, stk::SwitchStrategyFixedPriority< 32 >, stk::SwitchStrategyMonotonic< _Type >, stk::SwitchStrategyMonotonic< MSS_TYPE_DEADLINE >, stk::SwitchStrategyMonotonic< MSS_TYPE_RATE >, stk::SwitchStrategyRoundRobin, and stk::SwitchStrategySmoothWeightedRoundRobin.

Referenced by stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), and stk::test::TEST().

Here is the caller graph for this function:

◆ OnTaskSleep()

virtual void stk::ITaskSwitchStrategy::OnTaskSleep ( IKernelTask * task)
pure virtual

Notification that a task has entered sleep/blocked state.

Parameters
[in]taskPointer to the sleeping task,
Note
Sleep API. Implementations shall remove the task from runnable set here.

Implemented in stk::SwitchStrategyEDF, stk::SwitchStrategyFixedPriority< MAX_PRIORITIES >, stk::SwitchStrategyFixedPriority< 32 >, stk::SwitchStrategyMonotonic< _Type >, stk::SwitchStrategyMonotonic< MSS_TYPE_DEADLINE >, stk::SwitchStrategyMonotonic< MSS_TYPE_RATE >, stk::SwitchStrategyRoundRobin, and stk::SwitchStrategySmoothWeightedRoundRobin.

Referenced by stk::test::TEST().

Here is the caller graph for this function:

◆ OnTaskWake()

virtual void stk::ITaskSwitchStrategy::OnTaskWake ( IKernelTask * task)
pure virtual

Notification that a task is becoming runnable again.

Parameters
[in]taskPointer to the waking task
Note
Sleep API. Implementations shall re-insert the task into the runnable set here.

Implemented in stk::SwitchStrategyEDF, stk::SwitchStrategyFixedPriority< MAX_PRIORITIES >, stk::SwitchStrategyFixedPriority< 32 >, stk::SwitchStrategyMonotonic< _Type >, stk::SwitchStrategyMonotonic< MSS_TYPE_DEADLINE >, stk::SwitchStrategyMonotonic< MSS_TYPE_RATE >, stk::SwitchStrategyRoundRobin, and stk::SwitchStrategySmoothWeightedRoundRobin.

Referenced by stk::test::TEST().

Here is the caller graph for this function:

◆ RemoveTask()

virtual void stk::ITaskSwitchStrategy::RemoveTask ( IKernelTask * task)
pure virtual

The documentation for this class was generated from the following file: