Skip to content

Commit

Permalink
细节调整 chyyuu#19
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuyixiang committed May 7, 2020
1 parent bc4a96c commit b171b9f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 36 deletions.
5 changes: 3 additions & 2 deletions os/src/interrupt/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ fn supervisor_timer(context: &mut Context) -> *mut Context {
}

/// 出现未能解决的异常,终止当前线程
fn fault(_context: &mut Context, scause: Scause, _stval: usize) -> ! {
fn fault(_context: &mut Context, scause: Scause, _stval: usize) -> *mut Context {
println!("{:?} terminated with {:?}", PROCESSOR.get().current_thread(), scause.cause());
PROCESSOR.get().kill_current_thread();
PROCESSOR.get().run();
// 跳转到 PROCESSOR 调度的下一个线程
PROCESSOR.get().current_thread().run()
}
12 changes: 6 additions & 6 deletions os/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
// 所以在模块范围内不提示『未使用的函数』等警告
#![allow(dead_code)]

pub mod address;
pub mod config;
pub mod frame;
pub mod heap;
pub mod mapping;
pub mod range;
mod address;
mod config;
mod frame;
mod heap;
mod mapping;
mod range;

/// 一个缩写,模块中一些函数会使用
pub type MemoryResult<T> = Result<T, &'static str>;
Expand Down
8 changes: 4 additions & 4 deletions os/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ mod processor;
mod stack;
mod thread;

pub(self) use crate::interrupt::*;
pub(self) use crate::memory::*;
pub(self) use alloc::{sync::Arc, vec, vec::Vec};
pub(self) use spin::{Mutex, RwLock};
use crate::interrupt::*;
use crate::memory::*;
use alloc::sync::Arc;
use spin::{Mutex, RwLock};

pub use config::*;
pub use process::Process;
Expand Down
8 changes: 4 additions & 4 deletions os/src/process/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ lazy_static! {
pub struct Processor {
/// 当前正在执行的线程
current_thread: Option<Arc<Thread>>,
/// 线程调度器,其中不包括正在执行的线程
/// 线程调度器,记录所有线程
scheduler: SchedulerImpl<Arc<Thread>>,
}

Expand All @@ -38,7 +38,7 @@ impl Processor {
// 从 current_thread 中取出 Context
let thread = self.current_thread();
let context = thread.run();
// 因为这个线程(指的不是 thread,是运行 run 函数的线程)不会回来回收,所以手动 drop 掉 thread 的一个 Arc
// 这个函数不会执行到结尾,所以手动 drop 掉 thread 的一个 Arc
drop(thread);
// 从此将没有回头
unsafe {
Expand All @@ -64,7 +64,7 @@ impl Processor {
next_context
}
} else {
panic!("no more thread to run");
panic!("all threads terminated, shutting down");
}
}

Expand All @@ -87,7 +87,7 @@ impl Processor {
if let Some(next_thread) = self.scheduler.get_next() {
self.current_thread.replace(next_thread);
} else {
panic!("no more thread to run");
panic!("all threads terminated, shutting down");
}
}
}
20 changes: 0 additions & 20 deletions os/src/process/scheduler.rs

This file was deleted.

0 comments on commit b171b9f

Please sign in to comment.