Skip to main content

InterruptControl

Trait InterruptControl 

Source
pub unsafe trait InterruptControl {
    type State: Copy;

    const INIT: Self::State;

    // Required methods
    fn disable() -> Self::State;
    unsafe fn restore(state: Self::State);
}
Expand description

Strategy for disabling and restoring local (per-CPU) interrupts.

Implement this trait to tell the allocator how to disabling interrupts around a lock’s critical section, so the locked allocators are safe to call from interrupt context.

disable must save the prior state and then disable, returning that state; restore must put it back. Saving the prior state (rather than unconditionally re-enabling) is what makes nesting correct: an inner lock taken while an outer lock already disabled interrupts will, on release, restore “still disabled”, and only the outermost release re-enables.

§Safety

restore is unsafe: it changes the CPU interrupt-enable state and must be called exactly once, with the State returned by the matching disable, after the critical section. disable/restore need to be faithful inverses.

Required Associated Constants§

Source

const INIT: Self::State

A const-constructible placeholder used only to seed the lock’s saved-state.

Required Associated Types§

Source

type State: Copy

Opaque saved interrupt state.

Required Methods§

Source

fn disable() -> Self::State

Save the current local-interrupt state and disable interrupts on this CPU.

Source

unsafe fn restore(state: Self::State)

Restore the interrupt state previously returned by disable.

§Safety

Must be called once per disable, with that call’s returned state, after the critical section it guarded.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§