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

46 lines
1.1 KiB
Rust
Raw Normal View History

use alloc::String;
2018-06-03 19:05:43 +04:00
use memory::MemorySet;
use self::process::*;
2018-05-21 12:30:30 +04:00
pub use self::processor::*;
2018-06-03 19:05:43 +04:00
use spin::Once;
use sync::SpinNoIrqLock;
mod process;
mod processor;
2018-05-23 07:20:36 +04:00
mod scheduler;
2018-07-12 08:13:39 +04:00
pub fn init() {
2018-05-31 18:22:19 +04:00
PROCESSOR.call_once(|| {
SpinNoIrqLock::new({
2018-07-12 08:13:39 +04:00
let initproc = Process::new_init();
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-06-03 19:05:43 +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();
2018-06-03 19:05:43 +04:00
let 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());
}