BOOL arCreateTaskContext( struct TTaskContext FAR *TaskContext, TTaskStartupProc TaskStartupProc, SIZE StackSize );
Pointer to the task context descriptor structure.
Pointer to the task startup procedure (entry point), of type TTaskStartupProc.
Size of the task stack in bytes.
Returns TRUE on success or FALSE on failure. Use the stGetLastError function to obtain extended error information.
This function initializes the stack and execution context for a new task.
The first step performed by this function is the allocation of a memory buffer for the stack. The size of this
buffer is specified by the StackSize parameter. If the architecture dictates that the task context
(CPU registers) is stored on the stack, StackSize must be sufficient to hold both the context dump
and the task's runtime data. The task context is managed via the TTaskContext
descriptor, which provides all necessary information to resume task execution.
Typically, the context descriptor holds only the current stack pointer and the base address of the allocated stack memory (required for deallocation). While it is possible to store the entire register set within the descriptor itself, storing context data on the stack is generally recommended to minimize the processing overhead in the operating system scheduler.
During initialization, the function must set default values for CPU registers. The Instruction Pointer
(Program Counter) must be set to the address of the routine specified in TaskStartupProc.
Additionally, the interrupt enable flag (preemption flag) must be configured to ensure that task preemption
is enabled by default when the task begins execution.
The following steps outline the context creation process for the 80x86 architecture:
Task context resources are released using the arReleaseTaskContext function.
| Version: | 1.0 |
|---|---|
| Header file: | AR_API.h |
| See also: | arReleaseTaskContext, BOOL, context switching, FALSE, FAR, operating system scheduler, SIZE, stGetLastError, TRUE, TTaskContext, TTaskStartupProc |