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::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 ()=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)
 Notification that a task has exceeded its HRT deadline; returns whether the strategy can recover without a hard fault.
virtual void OnTaskWeightChange (IKernelTask *task, Weight old_weight)
 Notification that a runnable task's scheduling weight has changed.

Protected Member Functions

 ~ITaskSwitchStrategy ()=default
 Destructor.

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)
PRIORITY_INHERITANCE_API = 0 // (1) if strategy expects OnTaskWeightChange() events to support priority inheritance requests
};

Definition at line 1306 of file stk_common.h.

Constructor & Destructor Documentation

◆ ~ITaskSwitchStrategy()

stk::ITaskSwitchStrategy::~ITaskSwitchStrategy ( )
protecteddefault

Destructor.

Note
Protected by design. Prevents unsafe polymorphic delete.

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< TStrategyType >, stk::SwitchStrategyMonotonic< MSS_TYPE_DEADLINE >, stk::SwitchStrategyMonotonic< MSS_TYPE_RATE >, stk::SwitchStrategyRoundRobin, and stk::SwitchStrategySmoothWeightedRoundRobin.

◆ GetSize()

virtual size_t stk::ITaskSwitchStrategy::GetSize ( ) const
pure virtual

◆ OnTaskDeadlineMissed()

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

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.

Definition at line 1371 of file stk_common.h.

1372 {
1373 STK_UNUSED(task);
1374 return false;
1375 }
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:715

References STK_UNUSED.

◆ 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< TStrategyType >, stk::SwitchStrategyMonotonic< MSS_TYPE_DEADLINE >, stk::SwitchStrategyMonotonic< MSS_TYPE_RATE >, stk::SwitchStrategyRoundRobin, and stk::SwitchStrategySmoothWeightedRoundRobin.

◆ 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< TStrategyType >, stk::SwitchStrategyMonotonic< MSS_TYPE_DEADLINE >, stk::SwitchStrategyMonotonic< MSS_TYPE_RATE >, stk::SwitchStrategyRoundRobin, and stk::SwitchStrategySmoothWeightedRoundRobin.

◆ OnTaskWeightChange()

virtual void stk::ITaskSwitchStrategy::OnTaskWeightChange ( IKernelTask * task,
Weight old_weight )
inlinevirtual

Notification that a runnable task's scheduling weight has changed.

Parameters
[in]taskThe task whose weight was just updated via SetWeight().
[in]old_weightThe previous weight of this task (required to remove it from the priority list belonging to that weight).
Note
Called only for tasks that are currently in the runnable set (not sleeping). The strategy must relink the task to reflect its new weight. For strategies with WEIGHT_API = 0 this is a no-op. For SwitchStrategyFixedPriority it moves the task from its old priority-level list to the new one and updates m_ready_bitmap.
Called from within a ScopedCriticalSection.

Reimplemented in stk::SwitchStrategyFixedPriority< MAX_PRIORITIES >, and stk::SwitchStrategyFixedPriority< 32 >.

Definition at line 1389 of file stk_common.h.

1390 {
1391 STK_UNUSED(task);
1392 STK_UNUSED(old_weight);
1393 }

References STK_UNUSED.

◆ RemoveTask()

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

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