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};
|
2018-07-16 21:56:28 +04:00
|
|
|
pub use self::context::Context;
|
2018-07-17 15:06:30 +04:00
|
|
|
pub use ucore_process::processor::{*, Context as _whatever};
|
2018-07-16 21:56:28 +04:00
|
|
|
pub use ucore_process::scheduler::*;
|
2018-07-17 15:06:30 +04:00
|
|
|
pub use ucore_process::thread::*;
|
2018-04-27 19:10:39 +04:00
|
|
|
|
2018-07-16 20:23:02 +04:00
|
|
|
mod context;
|
2018-07-16 21:56:28 +04:00
|
|
|
|
|
|
|
type Processor = Processor_<Context, StrideScheduler>;
|
2018-04-27 19:10:39 +04:00
|
|
|
|
2018-07-12 08:13:39 +04:00
|
|
|
pub fn init() {
|
2018-07-16 20:23:02 +04:00
|
|
|
PROCESSOR.call_once(||
|
2018-07-17 06:47:05 +04:00
|
|
|
SpinNoIrqLock::new({
|
|
|
|
let mut processor = Processor::new(
|
|
|
|
unsafe { Context::new_init() },
|
|
|
|
// NOTE: max_time_slice <= 5 to ensure 'priority' test pass
|
|
|
|
StrideScheduler::new(5),
|
|
|
|
);
|
|
|
|
extern fn idle(arg: usize) -> ! {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
processor.add(Context::new_kernel(idle, 0));
|
|
|
|
processor
|
|
|
|
})
|
2018-07-16 20:23:02 +04:00
|
|
|
);
|
2018-04-27 19:10:39 +04:00
|
|
|
}
|
|
|
|
|
2018-05-31 18:22:19 +04:00
|
|
|
pub static PROCESSOR: Once<SpinNoIrqLock<Processor>> = Once::new();
|
2018-04-27 19:10:39 +04:00
|
|
|
|
2018-07-16 20:23:02 +04:00
|
|
|
pub fn processor() -> MutexGuard<'static, Processor, SpinNoIrq> {
|
|
|
|
PROCESSOR.try().unwrap().lock()
|
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 {
|
|
|
|
type Context = Context;
|
|
|
|
type Scheduler = StrideScheduler;
|
|
|
|
type ProcessorGuard = MutexGuard<'static, Processor, SpinNoIrq>;
|
|
|
|
|
|
|
|
fn processor() -> Self::ProcessorGuard {
|
|
|
|
processor()
|
|
|
|
}
|
2018-04-27 19:10:39 +04:00
|
|
|
}
|