Skip to main content

SpinMutex

Struct SpinMutex 

Source
pub struct SpinMutex<T: ?Sized> { /* private fields */ }
Expand description

IRQ-locking mutex for very short critical sections.

Acquiring the lock disables interrupts globally for the lifetime of the SpinMutexGuard; releasing it restores the previous interrupt state. Do not hold across blocking calls or .await points — the system will deadlock if a higher-priority interrupt is needed to make progress.

Maps to ove_irq_lock / ove_irq_unlock on the C side, which is itself a thin wrapper over the host RTOS’s interrupt-disable primitive (taskENTER_CRITICAL on FreeRTOS, irq_lock() on Zephyr, enter_critical_section() on NuttX, pthread_sigmask on POSIX).

Implementations§

Source§

impl<T> SpinMutex<T>

Source

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

Wrap value in a new SpinMutex.

Source

pub fn into_inner(self) -> T

Consume the mutex and return the wrapped value.

Source§

impl<T: ?Sized> SpinMutex<T>

Source

pub fn lock(&self) -> SpinMutexGuard<'_, T>

Acquire the lock by disabling interrupts. The returned guard restores them when dropped.

Source

pub fn with<R>(&self, f: impl FnOnce(&mut T) -> R) -> R

Run f with the value, restoring the IRQ state afterwards. Sugar around SpinMutex::lock that scopes the lock to the closure body.

Source

pub fn get_mut(&mut self) -> &mut T

Get a mutable reference without taking the lock. Sound because &mut self proves there are no other handles.

Trait Implementations§

Source§

impl<T: ?Sized + Send> Send for SpinMutex<T>

Source§

impl<T: ?Sized + Send> Sync for SpinMutex<T>

Auto Trait Implementations§

§

impl<T> !Freeze for SpinMutex<T>

§

impl<T> !RefUnwindSafe for SpinMutex<T>

§

impl<T> Unpin for SpinMutex<T>
where T: Unpin + ?Sized,

§

impl<T> UnsafeUnpin for SpinMutex<T>
where T: UnsafeUnpin + ?Sized,

§

impl<T> UnwindSafe for SpinMutex<T>
where T: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.