-
Notifications
You must be signed in to change notification settings - Fork 172
Closed
Description
What do you think about having a struct like zinc's NoInterrupts struct and passing it into the closure for the interrupt::free
function? The idea is to make a zero-sized struct that can't be created by users and is only ever created in a critical section. Then, if a function should only be called in a critical section it can take a reference to that struct which will guarantee that it will only be called in a critical section.
It would look something like this
mod interrupts {
pub fn disable() {}
pub fn enable() {}
pub struct CritToken {
_private: ()
}
pub fn free<F>(f: F)
where F: FnOnce(&CritToken)
{
disable();
f(&CritToken{ _private: () });
enable();
}
}
fn dangerous_func(tok: &interrupts::CritToken) {}
fn calling_dangerous_func() {
interrupts::free(|tok| {
dangerous_func(tok);
});
}
Metadata
Metadata
Assignees
Labels
No labels