1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-27 02:03:29 +04:00
rCore/src/process/mod.rs

57 lines
1.5 KiB
Rust
Raw Normal View History

use memory::MemoryController;
use spin::Once;
use sync::Mutex;
2018-05-13 11:06:44 +04:00
use core::slice;
use alloc::String;
use self::process::*;
2018-05-21 12:30:30 +04:00
pub use self::processor::*;
mod process;
mod processor;
2018-05-23 07:20:36 +04:00
mod scheduler;
pub fn init(mut mc: MemoryController) {
PROCESSOR.call_once(|| {Mutex::new({
let initproc = Process::new_init(&mut mc);
2018-05-31 16:26:25 +04:00
let idleproc = Process::new("idle", idle_thread, 0, &mut mc);
let mut processor = Processor::new();
processor.add(initproc);
processor.add(idleproc);
processor
})});
MC.call_once(|| Mutex::new(mc));
}
2018-05-21 12:30:30 +04:00
pub static PROCESSOR: Once<Mutex<Processor>> = Once::new();
pub static MC: Once<Mutex<MemoryController>> = Once::new();
2018-05-31 16:26:25 +04:00
extern fn idle_thread(arg: usize) -> ! {
loop {
println!("idle ...");
let mut i = 0;
2018-05-20 13:14:05 +04:00
while i < 1 << 22 {
i += 1;
}
}
2018-05-12 23:41:41 +04:00
}
2018-05-19 12:32:18 +04:00
pub fn add_user_process(name: impl AsRef<str>, data: &[u8]) {
let mut processor = PROCESSOR.try().unwrap().lock();
let mut mc = MC.try().unwrap().lock();
let mut new = Process::new_user(data, &mut mc);
2018-05-19 12:32:18 +04:00
new.name = String::from(name.as_ref());
processor.add(new);
}
2018-05-31 16:26:25 +04:00
pub fn add_kernel_process(entry: extern fn(usize) -> !, arg: usize) -> Pid {
let mut processor = PROCESSOR.try().unwrap().lock();
let mut mc = MC.try().unwrap().lock();
let mut new = Process::new("", entry, arg, &mut mc);
processor.add(new)
}
pub fn print() {
debug!("{:#x?}", *PROCESSOR.try().unwrap().lock());
}