Struct embassy_sync::mutex::Mutex
source · pub struct Mutex<M, T>{ /* 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§
source§impl<M, T> Mutex<M, T>
impl<M, T> Mutex<M, T>
sourcepub async fn lock(&self) -> MutexGuard<'_, M, T>
pub async fn lock(&self) -> MutexGuard<'_, M, T>
Lock the mutex.
This will wait for the mutex to be unlocked if it’s already locked.
sourcepub fn try_lock(&self) -> Result<MutexGuard<'_, M, T>, TryLockError>
pub fn try_lock(&self) -> Result<MutexGuard<'_, M, T>, TryLockError>
Attempt to immediately lock the mutex.
If the mutex is already locked, this will return an error instead of waiting.
sourcepub fn into_inner(self) -> Twhere
T: Sized,
pub fn into_inner(self) -> Twhere
T: Sized,
Consumes this mutex, returning the underlying data.