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