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

48 lines
1.2 KiB
Rust
Raw Normal View History

use memory::MemorySet;
use spin::Once;
2018-05-31 18:22:19 +04:00
use sync::SpinNoIrqLock;
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 ms: MemorySet) {
2018-05-31 18:22:19 +04:00
PROCESSOR.call_once(|| {
SpinNoIrqLock::new({
let initproc = Process::new_init(ms);
let idleproc = Process::new("idle", idle_thread, 0);
let mut processor = Processor::new();
processor.add(initproc);
processor.add(idleproc);
processor
})});
}
2018-05-31 18:22:19 +04:00
pub static PROCESSOR: Once<SpinNoIrqLock<Processor>> = Once::new();
2018-05-31 16:26:25 +04:00
extern fn idle_thread(arg: usize) -> ! {
loop {}
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 new = Process::new_user(data);
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 new = Process::new("", entry, arg);
2018-05-31 16:26:25 +04:00
processor.add(new)
}
pub fn print() {
debug!("{:#x?}", *PROCESSOR.try().unwrap().lock());
}