add #![deny(missing_docs)] AND #![deny(warnings)] in main.rs, and add more comments

This commit is contained in:
Yu Chen 2022-03-25 11:17:40 +08:00
parent 2b53281dd8
commit 745ea760d0
20 changed files with 126 additions and 13 deletions

View file

@ -1,3 +1,5 @@
//! Implementation of [`TaskContext`]
#[derive(Copy, Clone)]
#[repr(C)]
pub struct TaskContext {

View file

@ -1,3 +1,14 @@
//! 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`]. Control flow around this function
//! might not be what you expect.
mod context;
mod switch;
#[allow(clippy::module_inception)]
@ -12,6 +23,15 @@ use task::{TaskControlBlock, TaskStatus};
pub use context::TaskContext;
/// The task manager, where all the tasks are managed.
///
/// Functions implemented on `TaskManager` deals with all task state transitions
/// and task context switching. For convenience, you can find wrappers around it
/// in the module level.
///
/// Most of `TaskManager` are hidden behind the field `inner`, to defer
/// borrowing checks to runtime. You can see examples on how to use `inner` in
/// existing functions on `TaskManager`.
pub struct TaskManager {
/// total number of tasks
num_app: usize,
@ -82,7 +102,7 @@ impl TaskManager {
inner.tasks[current].task_status = TaskStatus::Exited;
}
/// Find next task to run and return app id.
/// Find next task to run and return task id.
///
/// In this case, we only return the first `Ready` task in task list.
fn find_next_task(&self) -> Option<usize> {

View file

@ -1,8 +1,17 @@
//! Rust wrapper around `__switch`.
//!
//! Switching to a different task's context happens here. The actual
//! implementation must not be in Rust and (essentially) has to be in assembly
//! language (Do you know why?), so this module really is just a wrapper around
//! `switch.S`.
use super::TaskContext;
use core::arch::global_asm;
global_asm!(include_str!("switch.S"));
extern "C" {
/// Switch to the context of `next_task_cx_ptr`, saving the current context
/// in `current_task_cx_ptr`.
pub fn __switch(current_task_cx_ptr: *mut TaskContext, next_task_cx_ptr: *const TaskContext);
}

View file

@ -1,9 +1,12 @@
//! Types related to task management
use super::TaskContext;
#[derive(Copy, Clone)]
pub struct TaskControlBlock {
pub task_status: TaskStatus,
pub task_cx: TaskContext,
// LAB1: Add whatever you need about the Task.
}
#[derive(Copy, Clone, PartialEq)]