Add comments in ch6
This commit is contained in:
parent
cea2febe35
commit
f9346edad1
35 changed files with 374 additions and 116 deletions
|
@ -1,25 +1,42 @@
|
|||
//! 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 whole operating system.
|
||||
//!
|
||||
//! A single global instance of [`Processor`] called `PROCESSOR` monitors running
|
||||
//! task(s) for each core.
|
||||
//!
|
||||
//! A single global instance of [`PidAllocator`] called `PID_ALLOCATOR` allocates
|
||||
//! pid for user apps.
|
||||
//!
|
||||
//! 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 manager;
|
||||
mod pid;
|
||||
mod processor;
|
||||
mod switch;
|
||||
#[allow(clippy::module_inception)]
|
||||
#[allow(rustdoc::private_intra_doc_links)]
|
||||
mod task;
|
||||
|
||||
use crate::fs::{open_file, OpenFlags};
|
||||
use alloc::sync::Arc;
|
||||
pub use context::TaskContext;
|
||||
use lazy_static::*;
|
||||
use manager::fetch_task;
|
||||
pub use manager::{fetch_task,TaskManager};
|
||||
use switch::__switch;
|
||||
use task::{TaskControlBlock, TaskStatus};
|
||||
|
||||
pub use manager::add_task;
|
||||
pub use pid::{pid_alloc, KernelStack, PidHandle};
|
||||
pub use pid::{pid_alloc, KernelStack, PidHandle,PidAllocator};
|
||||
pub use processor::{
|
||||
current_task, current_trap_cx, current_user_token, run_tasks, schedule, take_current_task,
|
||||
current_task, current_trap_cx, current_user_token, run_tasks, schedule, take_current_task,Processor
|
||||
};
|
||||
|
||||
/// Suspend the current 'Running' task and run the next task in task list.
|
||||
pub fn suspend_current_and_run_next() {
|
||||
// There must be an application running.
|
||||
let task = take_current_task().unwrap();
|
||||
|
@ -37,7 +54,7 @@ pub fn suspend_current_and_run_next() {
|
|||
// jump to scheduling cycle
|
||||
schedule(task_cx_ptr);
|
||||
}
|
||||
|
||||
/// Exit the current 'Running' task and run the next task in task list.
|
||||
pub fn exit_current_and_run_next(exit_code: i32) {
|
||||
// take from Processor
|
||||
let task = take_current_task().unwrap();
|
||||
|
@ -72,13 +89,14 @@ pub fn exit_current_and_run_next(exit_code: i32) {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
///Globle process that init user shell
|
||||
pub static ref INITPROC: Arc<TaskControlBlock> = Arc::new({
|
||||
let inode = open_file("initproc", OpenFlags::RDONLY).unwrap();
|
||||
let v = inode.read_all();
|
||||
TaskControlBlock::new(v.as_slice())
|
||||
});
|
||||
}
|
||||
|
||||
///Add init process to the manager
|
||||
pub fn add_initproc() {
|
||||
add_task(INITPROC.clone());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue