void arYield(void);
This function triggers a manual context switch, allowing the current task to voluntarily relinquish the CPU to another task.
The routine executes a sequence similar to the standard preemption handler. The recommended implementation workflow is as follows:
Disabling interrupts is mandatory to ensure the atomicity of the context switch and prevent scheduler re-entry. The interrupt enable state is intrinsic to each task and is preserved within its saved context. Explicit re-enabling of interrupts is generally not required within this function, as the state will be automatically restored when the next task resumes execution (assuming interrupts were enabled when that task was suspended).
The operating system context refers to a dedicated execution environment (specifically, a separate stack) used by the scheduler. This isolation ensures that the scheduler does not consume the stack space of user tasks. This context is initialized when the preemption handler is registered via the arSetPreemptiveHandler function. Please refer to its description for further details.
The scheduler function accepts a single parameter: a pointer to the global task context descriptor. It uses this
to save the state of the preempted task. When the scheduler decides which task to run next, it updates this global
descriptor. The arYield routine then uses this updated information to restore the context of the next
task to be executed.
| Version: | 1.0 |
|---|---|
| Header file: | AR_API.h |
| See also: | arSetPreemptiveHandler, context switching, operating system, operating system scheduler, TTaskContext |