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

56 lines
1.5 KiB
Rust
Raw Normal View History

2018-06-03 19:05:43 +04:00
use spin::Once;
2018-07-16 20:23:02 +04:00
use sync::{SpinNoIrqLock, Mutex, MutexGuard, SpinNoIrq};
pub use self::context::ContextImpl;
2018-10-23 20:38:22 +04:00
pub use ucore_process::*;
2018-07-17 15:06:30 +04:00
pub use ucore_process::thread::*;
use alloc::boxed::Box;
use consts::MAX_CPU_NUM;
use arch::cpu;
use alloc::sync::Arc;
use alloc::vec::Vec;
2018-07-16 20:23:02 +04:00
mod context;
2018-07-16 21:56:28 +04:00
2018-07-12 08:13:39 +04:00
pub fn init() {
// NOTE: max_time_slice <= 5 to ensure 'priority' test pass
2018-10-23 20:38:22 +04:00
let scheduler = Box::new(scheduler::RRScheduler::new(5));
let manager = Arc::new(ProcessManager::new(scheduler));
extern fn idle(_arg: usize) -> ! {
loop { cpu::halt(); }
}
for i in 0..MAX_CPU_NUM {
manager.add(ContextImpl::new_kernel(idle, i));
}
unsafe {
for cpu_id in 0..MAX_CPU_NUM {
PROCESSORS[cpu_id].init(cpu_id, ContextImpl::new_init(), manager.clone());
}
}
info!("process init end");
}
static PROCESSORS: [Processor; MAX_CPU_NUM] = [Processor::new(), Processor::new(), Processor::new(), Processor::new(), Processor::new(), Processor::new(), Processor::new(), Processor::new()];
pub fn processor() -> &'static Processor {
&PROCESSORS[cpu::id()]
2018-07-17 15:06:30 +04:00
}
#[allow(non_camel_case_types)]
pub type thread = ThreadMod<ThreadSupportImpl>;
pub mod thread_ {
pub type Thread = super::Thread<super::ThreadSupportImpl>;
}
pub struct ThreadSupportImpl;
impl ThreadSupport for ThreadSupportImpl {
fn processor() -> &'static Processor {
2018-07-17 15:06:30 +04:00
processor()
}
fn new_kernel(entry: extern fn(usize) -> !, arg: usize) -> Box<Context> {
ContextImpl::new_kernel(entry, arg)
}
}