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

48 lines
1.2 KiB
Rust
Raw Normal View History

use memory::MemoryController;
use spin::{Once, 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;
pub fn init(mut mc: MemoryController) {
PROCESSOR.call_once(|| {Mutex::new({
let initproc = Process::new_init(&mut mc);
let idleproc = Process::new("idle", idle_thread, &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-22 19:48:39 +04:00
extern fn idle_thread() -> ! {
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);
}
pub fn print() {
debug!("{:#x?}", *PROCESSOR.try().unwrap().lock());
}