Crate interrupts

source ·
Expand description

Cross-architecture utilities for temporarily disabling interrupts and signals.

This crate allows you to temporarily disable interrupts and then restore the previous state again.

Supported platforms:

  • bare-metal (kernel mode, target_os = "none")

    Disables hardware interrupts.

    • AArch64 (arch = aarch64)

    • 64-bit RISC-V (arch = riscv64)

    • x86-64 (arch = x86_64)

  • Unix (user mode, unix)

    Disables signals.

On targets with non-unix operating systems (not cfg!(unix)), this crate does nothing.

§Caveats

Interrupts are disabled on a best-effort basis.

Even though this crate makes sure that interrupts are disabled, nothing prevents you from manually enabling them again.

Manually dropping Guards may also cause interrupts to be enabled.

§Examples

Use disable to disable interrupts with a guard:

// interrupts may or may not be enabled
let guard = interrupts::disable();
// interrupts are disabled
drop(guard);
// interrupts are restored to the previous state

Use without to run a closure with disabled interrupts:

// interrupts may or may not be enabled
interrupts::without(|| {
    // interrupts are disabled
});
// interrupts are restored to the previous state
  • interrupt-ref-cell (A RefCell for sharing data with interrupt handlers or signal handlers on the same thread.)
  • interrupt-mutex (A mutex for sharing data with interrupt handlers or signal handlers.)

Structs§

Functions§

  • Temporarily disable interrupts.
  • Run a closure with disabled interrupts.