Struct BlockingMutex

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

Blocking mutex (not async)

Provides a blocking mutual exclusion primitive backed by an implementation of ScopedRawMutex.

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 CriticalSectionRawMutex when data can be shared between threads and interrupts.

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

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

Implementations§

Source§

impl<R: ConstInit, T> BlockingMutex<R, T>

Source

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

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

Source§

impl<R: ScopedRawMutex, T> BlockingMutex<R, T>

Source

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

Locks the raw mutex and grants temporary access to the inner data

Behavior when the lock is already locked is dependent on the behavior of the Raw mutex. See ScopedRawMutex::with_lock()’s documentation for more details

Source

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

Locks the raw mutex and grants temporary access to the inner data

Returns Some(U) if the lock was obtained. Returns None if the lock was already locked

Source§

impl<R, T> BlockingMutex<R, T>

Source

pub const fn const_new(raw_mutex: R, val: T) -> BlockingMutex<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

pub unsafe fn get_unchecked(&self) -> *mut T

Returns a pointer to the inner storage

§Safety

Must NOT be called when the lock is taken

Trait Implementations§

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<R, T> UnwindSafe for BlockingMutex<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.