# Module os::task

source · [−]
Expand description

Task management implementation

Everything about task management, like starting and switching tasks is implemented here.

A single global instance of `TaskManager` called `TASK_MANAGER` controls all the tasks in the operating system.

Be careful when you see `__switch` ASM function in `switch.S`. Control flow around this function might not be what you expect.

## Modules

context 🔒

Implementation of `TaskContext`

switch 🔒

Rust wrapper around `__switch`.

task 🔒

Types related to task management

## Structs

TASK_MANAGER

a `TaskManager` global instance through lazy_static!

TaskContext

task context structure containing some registers

TaskManager

The task manager, where all the tasks are managed.

TaskManagerInner 🔒

The task manager inner in ‘UPSafeCell’

## Functions

current_trap_cx

Get the current ‘Running’ task’s trap contexts.

current_user_token

Get the current ‘Running’ task’s token.

exit_current_and_run_next

Exit the current ‘Running’ task and run the next task in task list.

mark_current_exited 🔒

Change the status of current `Running` task into `Exited`.

mark_current_suspended 🔒

Change the status of current `Running` task into `Ready`.

run_first_task

Run the first task in task list.

run_next_task 🔒

Switch current `Running` task to the task we have found, or there is no `Ready` task and we can exit with all applications completed

suspend_current_and_run_next

Suspend the current ‘Running’ task and run the next task in task list.