Expand description
Preemption guard — disables preemption for the lifetime of the guard.
§When to use
Use PreemptGuard to protect per-CPU data structures that are only
accessed from the CPU that owns them. Because no other CPU can touch
them, a spin-lock is unnecessary — disabling preemption (so the current
CPU cannot switch tasks mid-operation) is sufficient.
ⓘ
let _guard = PreemptGuard::new();
// safe to read/write per-CPU data here
// guard is dropped at end of scope → preemption re-enabled§What it does NOT protect
PreemptGuard does not protect against concurrent access from other
CPUs. For shared data, use crate::sync::SpinLock instead.
§Nesting
Guards can be nested: each PreemptGuard::new() increments the per-CPU
preemption depth and each drop decrements it. Preemption is re-enabled
only when the depth reaches 0.
Structs§
- Preempt
Guard - RAII guard that disables preemption on the current CPU.