Function agb::interrupt::add_interrupt_handler
source · pub unsafe fn add_interrupt_handler(
interrupt: Interrupt,
handler: impl Fn(CriticalSection<'_>) + Send + Sync + 'static,
) -> InterruptHandler
Expand description
Adds an interrupt handler as long as the returned value is alive. The
closure takes a CriticalSection
which can be used for mutexes.
§Safety
- You must not allocate in an interrupt.
- Many functions in agb allocate and it isn’t always clear.
§Staticness
- The closure must be static because forgetting the interrupt handler would cause a use after free.
§Examples
use critical_section::CriticalSection;
use agb::interrupt::{add_interrupt_handler, Interrupt};
// Safety: doesn't allocate
let _a = unsafe {
add_interrupt_handler(Interrupt::VBlank, |_: CriticalSection| {
agb::println!("Woah there! There's been a vblank!");
})
};