Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-29: Switch IRQ handler's map from BTreeMap to array #35

Merged
merged 2 commits into from
Oct 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions kernel/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ use crate::{
net::process_packets,
};
use alloc::boxed::Box;
use alloc::collections::BTreeMap;

// TODO: Use a simple array for faster access.
static IRQ_HANDLERS: SpinLock<BTreeMap<u8, Box<dyn FnMut() + Send + Sync>>> =
SpinLock::new(BTreeMap::new());
const DEFAULT_IRQ_HANDLER: Option<Box<dyn FnMut() + Send + Sync>> = None;
static IRQ_HANDLERS: SpinLock<[Option<Box<dyn FnMut() + Send + Sync>>; 256]> =
SpinLock::new([DEFAULT_IRQ_HANDLER; 256]);

pub fn attach_irq<F: FnMut() + Send + Sync + 'static>(irq: u8, f: F) {
IRQ_HANDLERS.lock().insert(irq, Box::new(f));
IRQ_HANDLERS.lock()[irq as usize] = Some(Box::new(f));
enable_irq(irq);
}

pub fn handle_irq(irq: u8) {
if let Some(handler) = IRQ_HANDLERS.lock().get_mut(&irq) {
if let Some(handler) = &mut IRQ_HANDLERS.lock()[irq as usize] {
(*handler)();
process_packets();
}
Expand Down