use core::sync::atomic::{AtomicBool, Ordering};
use trapframe::TrapFrame;
use crate::{arch::irq::IRQ_LIST, cpu::CpuException, cpu_local};
pub(crate) fn call_irq_callback_functions(trap_frame: &TrapFrame) {
IN_INTERRUPT_CONTEXT.store(true, Ordering::Release);
let irq_line = IRQ_LIST.get().unwrap().get(trap_frame.trap_num).unwrap();
let callback_functions = irq_line.callback_list();
for callback_function in callback_functions.iter() {
callback_function.call(trap_frame);
}
drop(callback_functions);
if !CpuException::is_cpu_exception(trap_frame.trap_num as u16) {
crate::arch::interrupts_ack();
}
IN_INTERRUPT_CONTEXT.store(false, Ordering::Release);
crate::arch::irq::enable_local();
crate::trap::softirq::process_pending();
}
cpu_local! {
static IN_INTERRUPT_CONTEXT: AtomicBool = AtomicBool::new(false);
}
pub fn in_interrupt_context() -> bool {
IN_INTERRUPT_CONTEXT.load(Ordering::Acquire)
}