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::*;
|
2018-04-27 19:10:39 +04:00
|
|
|
|
2019-02-18 17:45:50 +04:00
|
|
|
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
|
2019-02-23 15:21:12 +04:00
|
|
|
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
|
|
|
|
2018-11-17 08:39:48 +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());
|
2018-11-17 08:39:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 11:57:34 +04:00
|
|
|
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");
|
2018-04-27 19:10:39 +04:00
|
|
|
}
|
|
|
|
|
2019-03-27 14:35:08 +04:00
|
|
|
static PROCESSORS: [Processor; MAX_CPU_NUM] = [
|
2019-04-16 14:13:55 +04:00
|
|
|
// 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
|
|
|
///
|
2019-05-04 09:16:42 +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)
|
2018-11-06 17:44:12 +04:00
|
|
|
}
|