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

133 lines
4.1 KiB
Rust
Raw Normal View History

2019-01-25 18:58:49 +04:00
pub use self::structs::*;
2018-11-19 13:21:06 +04:00
use crate::arch::cpu;
2019-03-27 14:35:08 +04:00
use crate::consts::{MAX_CPU_NUM, MAX_PROCESS_NUM};
2019-03-29 09:23:49 +04:00
use crate::sync::{MutexGuard, SpinNoIrq};
2018-12-17 19:54:13 +04:00
use alloc::{boxed::Box, sync::Arc};
2018-11-19 13:21:06 +04:00
use log::*;
2019-03-27 14:35:08 +04:00
pub use rcore_thread::*;
mod abi;
2019-03-27 14:35:08 +04:00
pub mod structs;
2018-11-19 21:08:39 +04:00
2018-07-12 08:13:39 +04:00
pub fn init() {
2018-11-03 17:45:03 +04:00
// NOTE: max_time_slice <= 5 to ensure 'priority' test pass
let scheduler = scheduler::RRScheduler::new(5);
2019-01-24 15:03:45 +04:00
let manager = Arc::new(ThreadPool::new(scheduler, MAX_PROCESS_NUM));
2018-11-03 17:45:03 +04:00
unsafe {
for cpu_id in 0..MAX_CPU_NUM {
2019-01-25 18:58:49 +04:00
PROCESSORS[cpu_id].init(cpu_id, Thread::new_init(), manager.clone());
}
}
crate::shell::add_user_shell();
2018-11-03 17:45:03 +04:00
2019-03-18 14:20:27 +04:00
info!("process: init end");
}
2019-03-27 14:35:08 +04:00
static PROCESSORS: [Processor; MAX_CPU_NUM] = [
// TODO: More elegant ?
2019-04-19 08:34:27 +04:00
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
// Processor::new(), Processor::new(), Processor::new(), Processor::new(),
2019-03-27 14:35:08 +04:00
];
2018-11-03 17:45:03 +04:00
2019-01-25 18:58:49 +04:00
/// Get current thread
2018-12-13 22:37:51 +04:00
///
/// `Thread` is a thread-local object.
/// It is safe to call this once, and pass `&mut Thread` as a function argument.
pub unsafe fn current_thread() -> &'static mut Thread {
// trick: force downcast from trait object
let (process, _): (&mut Thread, *const ()) = core::mem::transmute(processor().context());
2018-11-03 17:45:03 +04:00
process
2018-07-17 15:06:30 +04:00
}
2018-11-03 17:45:03 +04:00
// Implement dependencies for std::thread
2018-07-17 15:06:30 +04:00
2018-11-03 17:45:03 +04:00
#[no_mangle]
pub fn processor() -> &'static Processor {
&PROCESSORS[cpu::id()]
}
#[no_mangle]
2019-03-27 14:35:08 +04:00
pub fn new_kernel_context(entry: extern "C" fn(usize) -> !, arg: usize) -> Box<Context> {
2019-01-25 18:58:49 +04:00
Thread::new_kernel(entry, arg)
}