pub struct IrqCell<T: ?Sized> { /* private fields */ }Available on crate feature
full and non-crate feature use_std only.Expand description
An interrupt safe, single-threaded mutable memory location.
This prevents deadlocks between interrupt handlers and main kernel code by keeping interrupts disabled during the time a lock is held.
Implementations§
Source§impl<T: ?Sized> IrqCell<T>
impl<T: ?Sized> IrqCell<T>
Sourcepub fn lock(&self) -> IrqGuard<'_, T>
pub fn lock(&self) -> IrqGuard<'_, T>
Locks the IrqCell, disabling interrupts on the current CPU.
§Panics
This function will panic if the IrqCell is already locked by the current CPU.
§Examples
use kernel_api::sync::IrqCell;
let c = IrqCell::new(5);
{
let mut guard = c.lock();
// Interrupts are now disabled to the end of this block
*guard = 10;
}
assert_eq!(*c.lock(), 10);Causing a deadlock will cause a panic:
ⓘ
use kernel_api::sync::IrqCell;
let c = IrqCell::new(5);
let x = c.lock();
let y = c.lock();