ARM: Use RwLock to wrap raspi3 IRQ handler
use crate::arch::interrupt::TrapFrame;
use bcm2837::interrupt::Controller;
+use spin::RwLock;
pub use bcm2837::interrupt::Interrupt;
-static IRQ_HANDLERS: &'static [Option<fn()>; 64] = &[None; 64];
+lazy_static! {
+ static ref IRQ_HANDLERS: RwLock<[Option<fn()>; 64]> = RwLock::new([None; 64]);
+}
pub fn is_timer_irq() -> bool {
super::timer::is_pending()
@@ -11,15 +14,13 @@ pub fn is_timer_irq() -> bool {
pub fn handle_irq(_tf: &mut TrapFrame) {
for int in Controller::new().pending_interrupts() {
- if let Some(handler) = IRQ_HANDLERS[int] {
+ if let Some(handler) = IRQ_HANDLERS.read()[int] {
handler();
}
}
}
pub fn register_irq(int: Interrupt, handler: fn()) {
- unsafe {
- *(&IRQ_HANDLERS[int as usize] as *const _ as *mut Option<fn()>) = Some(handler);
- }
+ IRQ_HANDLERS.write()[int as usize] = Some(handler);
Controller::new().enable(int);
}
