From 52d3443e0591f518c21183380c86001f651c7f97 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Tue, 17 Jul 2018 10:47:05 +0800 Subject: [PATCH] Recover idle process. Make shell wait for the user it spawned. --- kernel/src/fs.rs | 5 +++-- kernel/src/process/mod.rs | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/kernel/src/fs.rs b/kernel/src/fs.rs index fbb76d7..f45b6ee 100644 --- a/kernel/src/fs.rs +++ b/kernel/src/fs.rs @@ -29,9 +29,10 @@ pub fn shell() { continue; } if let Ok(file) = root.borrow().lookup(name.as_str()) { - let len = file.borrow().read_at(0, &mut *buf).unwrap(); use process::*; - processor().add(Context::new_user(&buf[..len])); + let len = file.borrow().read_at(0, &mut *buf).unwrap(); + let pid = processor().add(Context::new_user(&buf[..len])); + processor().current_wait_for(pid); } else { println!("Program not exist"); } diff --git a/kernel/src/process/mod.rs b/kernel/src/process/mod.rs index 61dc0de..84a86f5 100644 --- a/kernel/src/process/mod.rs +++ b/kernel/src/process/mod.rs @@ -10,11 +10,18 @@ type Processor = Processor_; pub fn init() { PROCESSOR.call_once(|| - SpinNoIrqLock::new(Processor::new( - unsafe { Context::new_init() }, - // NOTE: max_time_slice <= 5 to ensure 'priority' test pass - StrideScheduler::new(5), - )) + SpinNoIrqLock::new({ + let mut processor = Processor::new( + unsafe { Context::new_init() }, + // NOTE: max_time_slice <= 5 to ensure 'priority' test pass + StrideScheduler::new(5), + ); + extern fn idle(arg: usize) -> ! { + loop {} + } + processor.add(Context::new_kernel(idle, 0)); + processor + }) ); }