I have the following types and functions in my code:
type IrqList = FnvIndexMap<u8, MiniVec<fn(InterruptStackFrameValue)>, U256>;
//...
static ref IRQ_FUNCS: RwLock<IrqList> = RwLock::new({
//...
pub fn register_interrupt_handler(interrupt: u8, func: fn(InterruptStackFrameValue)) -> usize
//...
And I call the above fn like so:
register_interrupt_handler(self.intline, |_| self.cqs.iter().enumerate().for_each(|(i, queue)| queue.read_new_entries(&mut self.resps[i])));
But when I compile it, I get:
error[E0308]: mismatched types
--> libk\src\nvme\mod.rs:695:50
|
695 | ...(self.intline, |_| self.cqs.iter().enumerate().for_each(|(i, queue)| queue.read_new_entries(&mut self.resps[i])));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found closure
|
= note: expected fn pointer `fn(InterruptStackFrameValue)`
found closure `[closure@libk\src\nvme\mod.rs:695:50: 695:147]`
I understand that this might have lifetime issues, too, but I'm kinda confused. When I originally had this function prototype defined, it took no arguments and I could happily register interrupt handlers all day with it. But now, when I introduce the stack frame, it complains about it. I've tried Box
ing it, which gives me the lifetime error. My question is: how do I register this handler in such a way that I can have it only affect this particular instance of it? I could do an interrupt handler for all of the devices that this driver is able to work with -- all the devices that I've found, I mean. But the problem is that each device may have a different interrupt number, and though I could change that interrupt vector, I don't really want to. I could register the same handler for every new interrupt vector I get, but that seems like a waste to me -- I'd have multiple interrupts doing the same thing. Is there any way to do this or should I just register a handler that scans all the devices and runs this code on each one?