Function hermit_sync::without_interrupts
source · pub fn without_interrupts<F, R>(f: F) -> Rwhere
F: FnOnce() -> R,Expand description
Run a closure with disabled interrupts.
Run the given closure, disabling interrupts before running it (if they aren’t already disabled). Afterward, interrupts are enabled again if they were enabled before.
If you have other enable and disable calls within the closure, things may not work as expected.
Only has an effect if target_os = "none".
Synchronization
This synchronizes the current thread with itself via a compiler_fence.
A compiler fence is sufficient for sharing a !Sync type, such as RefCell, with an interrupt handler on the same hardware thread (core).
Examples
// interrupts may or may not be enabled
interrupts::without(|| {
// interrupts are disabled
});
// interrupts are restored to the previous stateNesting:
// interrupts may be enabled
interrupts::without(|| {
// interrupts are disabled
interrupts::without(|| {
// interrupts are disabled
});
// interrupts are still disabled
});
// interrupts are restored