Skip to main content

IrqCell

Struct IrqCell 

Source
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> IrqCell<T>

Source

pub const fn new(val: T) -> Self

Creates a new IrqCell containing val.

§Examples
use kernel_api::sync::IrqCell;

let c = IrqCell::new(5);
Source§

impl<T: ?Sized> IrqCell<T>

Source

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();
Source

pub unsafe fn make_guard_unchecked(&self) -> IrqGuard<'_, T>

Creates a new IrqGuard without checking if the IrqCell is locked.

§Safety

The IrqCell must already be logically locked by the current CPU.

Only one IrqGuard must exist at any one time.

Source

pub unsafe fn unlock(&self)

Forcibly unlocks the IrqCell.

This is useful when combined with mem::forget to keep an IrqCell locked without holding onto a IrqGuard.

§Safety

The current CPU must logically own an IrqGuard that has discarded in a way that prevents its [Drop] impl being called.

Trait Implementations§

Source§

impl<T: Debug> Debug for IrqCell<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for IrqCell<T>

§

impl<T> !RefUnwindSafe for IrqCell<T>

§

impl<T> !Sync for IrqCell<T>

§

impl<T> Send for IrqCell<T>
where UnsafeCell<T>: Send, T: ?Sized,

§

impl<T> Unpin for IrqCell<T>
where UnsafeCell<T>: Unpin, T: ?Sized,

§

impl<T> UnsafeUnpin for IrqCell<T>
where UnsafeCell<T>: UnsafeUnpin, T: ?Sized,

§

impl<T> UnwindSafe for IrqCell<T>
where UnsafeCell<T>: UnwindSafe, T: ?Sized,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = !

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.