update comments
This commit is contained in:
parent
5b9dfeb6ad
commit
676fdd86b7
4 changed files with 32 additions and 12 deletions
|
@ -1,14 +1,19 @@
|
|||
//! Implementation of [`TaskContext`]
|
||||
|
||||
/// Task Context
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct TaskContext {
|
||||
/// return address ( e.g. __restore ) of __switch ASM function
|
||||
ra: usize,
|
||||
/// kernel stack pointer of app
|
||||
sp: usize,
|
||||
/// callee saved registers: s 0..11
|
||||
s: [usize; 12],
|
||||
}
|
||||
|
||||
impl TaskContext {
|
||||
/// init task context
|
||||
pub fn zero_init() -> Self {
|
||||
Self {
|
||||
ra: 0,
|
||||
|
@ -16,6 +21,8 @@ impl TaskContext {
|
|||
s: [0; 12],
|
||||
}
|
||||
}
|
||||
|
||||
/// set task context {__restore ASM funciton, kernel stack, s_0..12 }
|
||||
pub fn goto_restore(kstack_ptr: usize) -> Self {
|
||||
extern "C" {
|
||||
fn __restore();
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
//! A single global instance of [`TaskManager`] called `TASK_MANAGER` controls
|
||||
//! all the tasks in the operating system.
|
||||
//!
|
||||
//! Be careful when you see [`__switch`]. Control flow around this function
|
||||
//! Be careful when you see `__switch` ASM function in `switch.S`. Control flow around this function
|
||||
//! might not be what you expect.
|
||||
|
||||
mod context;
|
||||
mod switch;
|
||||
|
||||
#[allow(clippy::module_inception)]
|
||||
mod task;
|
||||
|
||||
|
@ -39,7 +40,8 @@ pub struct TaskManager {
|
|||
inner: UPSafeCell<TaskManagerInner>,
|
||||
}
|
||||
|
||||
struct TaskManagerInner {
|
||||
/// Inner of Task Manager
|
||||
pub struct TaskManagerInner {
|
||||
/// task list
|
||||
tasks: [TaskControlBlock; MAX_APP_NUM],
|
||||
/// id of current `Running` task
|
||||
|
@ -47,6 +49,7 @@ struct TaskManagerInner {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
/// Global variable: TASK_MANAGER
|
||||
pub static ref TASK_MANAGER: TaskManager = {
|
||||
let num_app = get_num_app();
|
||||
let mut tasks = [TaskControlBlock {
|
||||
|
@ -135,27 +138,33 @@ impl TaskManager {
|
|||
}
|
||||
}
|
||||
|
||||
/// run first task
|
||||
pub fn run_first_task() {
|
||||
TASK_MANAGER.run_first_task();
|
||||
}
|
||||
|
||||
/// rust next task
|
||||
fn run_next_task() {
|
||||
TASK_MANAGER.run_next_task();
|
||||
}
|
||||
|
||||
/// suspend current task
|
||||
fn mark_current_suspended() {
|
||||
TASK_MANAGER.mark_current_suspended();
|
||||
}
|
||||
|
||||
/// exit current task
|
||||
fn mark_current_exited() {
|
||||
TASK_MANAGER.mark_current_exited();
|
||||
}
|
||||
|
||||
/// suspend current task, then run next task
|
||||
pub fn suspend_current_and_run_next() {
|
||||
mark_current_suspended();
|
||||
run_next_task();
|
||||
}
|
||||
|
||||
/// exit current task, then run next task
|
||||
pub fn exit_current_and_run_next() {
|
||||
mark_current_exited();
|
||||
run_next_task();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue