pub struct Guard { /* private fields */ }
Expand description
An interrupt guard.
Created using disable
.
While an instance of this guard is held, interrupts are disabled. When this guard is dropped, interrupts are restored to the state before disabling.
§Caveats (Drop Order)
If interrupts are enabled, acquiring a guard will disable them.
Dropping this guard will enable interrupts again.
Different Guard
s might be dropped in arbitrary order.
This may result in interrupts being enabled again, even though another Guard
is still held.
For this to happen, one must explicitly drop guards in the wrong order, though.
As long as guards don’t leave their original drop scope, they are dropped automatically in the correct order.
§Examples
// interrupts may or may not be enabled
let guard = interrupts::disable();
// interrupts are disabled
drop(guard);
// interrupts are restored to the previous state
Dropping guards in the wrong order (don’t do this):
// Interrupts are enabled
let a = interrupts::disable();
// Interrupts are disabled
let b = interrupts::disable();
drop(a);
// Interrupts are enabled, although we still hold a guard in b
drop(b);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Guard
impl RefUnwindSafe for Guard
impl !Send for Guard
impl !Sync for Guard
impl Unpin for Guard
impl UnwindSafe for Guard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more