embassy_sync::blocking_mutex

Struct Mutex

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

Blocking mutex (not async)

Provides a blocking mutual exclusion primitive backed by an implementation of raw::RawMutex.

Which implementation you select depends on the context in which you’re using the mutex, and you can choose which kind of interior mutability fits your use case.

Use CriticalSectionMutex when data can be shared between threads and interrupts.

Use NoopMutex when data is only shared between tasks running on the same executor.

Use [ThreadModeMutex] when data is shared between tasks running on the same executor but you want a global singleton.

In all cases, the blocking mutex is intended to be short lived and not held across await points. Use the async Mutex if you need a lock that is held across await points.

Implementations§

Source§

impl<R: RawMutex, T> Mutex<R, T>

Source

pub const fn new(val: T) -> Mutex<R, T>

Creates a new mutex in an unlocked state ready for use.

Source

pub fn lock<U>(&self, f: impl FnOnce(&T) -> U) -> U

Creates a critical section and grants temporary access to the protected data.

Source§

impl<R, T> Mutex<R, T>

Source

pub const fn const_new(raw_mutex: R, val: T) -> Mutex<R, T>

Creates a new mutex based on a pre-existing raw mutex.

This allows creating a mutex in a constant context on stable Rust.

Source

pub fn into_inner(self) -> T

Consumes this mutex, returning the underlying data.

Source

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

Returns a mutable reference to the underlying data.

Since this call borrows the Mutex mutably, no actual locking needs to take place—the mutable borrow statically guarantees no locks exist.

Source§

impl<T> Mutex<CriticalSectionRawMutex, T>

Source

pub fn borrow<'cs>(&'cs self, _cs: CriticalSection<'cs>) -> &'cs T

Borrows the data for the duration of the critical section

Source§

impl<T> Mutex<NoopRawMutex, T>

Source

pub fn borrow(&self) -> &T

Borrows the data

Trait Implementations§

Source§

impl<R: RawMutex + Send, T: ?Sized + Send> Send for Mutex<R, T>

Source§

impl<R: RawMutex + Sync, T: ?Sized + Send> Sync for Mutex<R, T>

Auto Trait Implementations§

§

impl<R, T> !Freeze for Mutex<R, T>

§

impl<R, T> !RefUnwindSafe for Mutex<R, T>

§

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

§

impl<R, T> UnwindSafe for Mutex<R, T>
where R: UnwindSafe, 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.