xref: /DragonOS/kernel/src/arch/x86_64/process/idle.rs (revision 2b7818e80e00fcfe4d03533f587cc125ea5e4bec)
1 use core::hint::spin_loop;
2 
3 use log::error;
4 
5 use crate::{
6     arch::CurrentIrqArch,
7     exception::InterruptArch,
8     process::{ProcessFlags, ProcessManager},
9     sched::{SchedMode, __schedule},
10 };
11 
12 impl ProcessManager {
13     /// 每个核的idle进程
14     pub fn arch_idle_func() -> ! {
15         loop {
16             let pcb = ProcessManager::current_pcb();
17             if pcb.flags().contains(ProcessFlags::NEED_SCHEDULE) {
18                 __schedule(SchedMode::SM_NONE);
19             }
20             if CurrentIrqArch::is_irq_enabled() {
21                 unsafe {
22                     x86::halt();
23                 }
24             } else {
25                 error!("Idle process should not be scheduled with IRQs disabled.");
26                 spin_loop();
27             }
28         }
29     }
30 }
31