Struct embassy_sync::blocking_mutex::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>,

§

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

§

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.