zephyr::sync

Struct SpinMutex

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

A lower-level mutual exclusion primitive for protecting data.

This is modeled after [sync::Mutex] but instead of using k_mutex from Zephyr, it uses k_spinlock. It’s main advantage is that it is usable from IRQ context. However, it also is uninterruptible, and prevents even IRQ handlers from running.

Implementations§

source§

impl<T> SpinMutex<T>

source

pub const fn new(t: T) -> SpinMutex<T>

Construct a new wrapped Mutex.

source§

impl<T: ?Sized> SpinMutex<T>

source

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

Acquire a mutex, spinning as needed to aquire the controlling spinlock.

This function will spin the current thread until it is able to acquire the spinlock. Returns an RAII guard to allow scoped unlock of the lock. When the guard goes out of scope, the SpinMutex will be unlocked.

source

pub fn try_lock(&self) -> Result<SpinMutexGuard<'_, T>, SpinTryLockError>

Attempts to aquire this lock.

If the lock could not be aquired at this time, then Err is returned. Otherwise an RAII guard is returned. The lock will be unlocked when the guard is dropped.

This function does not block.

Trait Implementations§

source§

impl<T> Debug for SpinMutex<T>

source§

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

Formats the value using the given formatter. Read more
source§

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

As the data is protected by spinlocks, with RAII ensuring the lock is always released, this satisfies Rust’s requirements for Send and Sync. The dependency of both on “Send” of the data type is intentional, as it is the Mutex that is providing the Sync semantics. However, it only makes sense for types that are usable from multiple thread contexts.

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> 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.