pub struct Mutex<M, T>where
    M: RawMutex,
    T: ?Sized,
{ /* private fields */ }
Expand description

Async mutex.

The mutex is generic over a blocking RawMutex. The raw mutex is used to guard access to the internal “is locked” flag. It is held for very short periods only, while locking and unlocking. It is not held for the entire time the async Mutex is locked.

Which implementation you select depends on the context in which you’re using the mutex.

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

Use NoopRawMutex 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 singleton.

Implementations

Async mutex.

Create a new mutex with the given value.

Lock the mutex.

This will wait for the mutex to be unlocked if it’s already locked.

Attempt to immediately lock the mutex.

If the mutex is already locked, this will return an error instead of waiting.

Consumes this mutex, returning the underlying data.

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.

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.