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>
impl<T> SpinMutex<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume the mutex and return the wrapped value.
Source§impl<T: ?Sized> SpinMutex<T>
impl<T: ?Sized> SpinMutex<T>
Sourcepub fn lock(&self) -> SpinMutexGuard<'_, T>
pub fn lock(&self) -> SpinMutexGuard<'_, T>
Acquire the lock by disabling interrupts. The returned guard restores them when dropped.
Sourcepub fn with<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
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.