pub struct RwLock<M, T>{ /* private fields */ }
Expand description
Async read-write lock.
The read-write lock is generic over the raw mutex implementation M
and the data T
it protects.
The raw read-write lock is used to guard access to the internal state. It
is held for very short periods only, while locking and unlocking. It is not held
for the entire time the async RwLock is locked.
Which implementation you select depends on the context in which you’re using the read-write lock.
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> RwLock<M, T>
impl<M, T> RwLock<M, T>
Sourcepub fn read(&self) -> impl Future<Output = RwLockReadGuard<'_, M, T>>
pub fn read(&self) -> impl Future<Output = RwLockReadGuard<'_, M, T>>
Lock the read-write lock for reading.
This will wait for the lock to be available if it’s already locked for writing.
Sourcepub fn write(&self) -> impl Future<Output = RwLockWriteGuard<'_, M, T>>
pub fn write(&self) -> impl Future<Output = RwLockWriteGuard<'_, M, T>>
Lock the read-write lock for writing.
This will wait for the lock to be available if it’s already locked for reading or writing.
Sourcepub fn try_read(&self) -> Result<RwLockReadGuard<'_, M, T>, TryLockError>
pub fn try_read(&self) -> Result<RwLockReadGuard<'_, M, T>, TryLockError>
Attempt to immediately lock the rwlock.
If the rwlock is already locked, this will return an error instead of waiting.
Sourcepub fn try_write(&self) -> Result<RwLockWriteGuard<'_, M, T>, TryLockError>
pub fn try_write(&self) -> Result<RwLockWriteGuard<'_, M, T>, TryLockError>
Attempt to immediately lock the rwlock.
If the rwlock 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 read-write lock, returning the underlying data.