pub struct RwLock<T>(/* private fields */)
where
T: Sized;Expand description
A reader-writer lock.
This type of lock allows a number of readers or at most one writer at any point in time. The write portion of this lock typically allows modification of the underlying data (exclusive access) and the read portion of this lock typically allows for read-only access (shared access).
Implementations§
Source§impl<T> RwLock<T>where
T: Sized,
impl<T> RwLock<T>where
T: Sized,
Sourcepub fn clear_poison(&self)
pub fn clear_poison(&self)
Clear the poisoned state from a read-write lock.
If the lock is poisoned, it will remain poisoned until this function is called. This allows recovering from a poisoned state and marking that it has recovered. For example, if the value is overwritten by a known-good value, then the lock can be marked as un-poisoned.
If the inner lock is a Tokio lock, this function will do nothing.
Sourcepub fn is_poisoned(&self) -> bool
pub fn is_poisoned(&self) -> bool
Returns true if the lock is poisoned.
Sourcepub async fn read(
&self,
) -> Result<RwLockReadGuard<'_, T>, PoisonError<RwLockReadGuard<'_, T>>>
pub async fn read( &self, ) -> Result<RwLockReadGuard<'_, T>, PoisonError<RwLockReadGuard<'_, T>>>
Locks this RwLock with shared read access, blocking the current thread until it can be acquired.
Sourcepub async fn try_read(
&self,
) -> Result<RwLockReadGuard<'_, T>, TryLockError<RwLockReadGuard<'_, T>>>
pub async fn try_read( &self, ) -> Result<RwLockReadGuard<'_, T>, TryLockError<RwLockReadGuard<'_, T>>>
Attempts to lock this RwLock with shared read access, returning immediately if it cannot be acquired.
Sourcepub async fn write(
&self,
) -> Result<RwLockWriteGuard<'_, T>, PoisonError<RwLockWriteGuard<'_, T>>>
pub async fn write( &self, ) -> Result<RwLockWriteGuard<'_, T>, PoisonError<RwLockWriteGuard<'_, T>>>
Locks this RwLock with exclusive write access, blocking the current thread until it can be acquired.
Sourcepub async fn try_write(
&self,
) -> Result<RwLockWriteGuard<'_, T>, TryLockError<RwLockWriteGuard<'_, T>>>
pub async fn try_write( &self, ) -> Result<RwLockWriteGuard<'_, T>, TryLockError<RwLockWriteGuard<'_, T>>>
Attempts to lock this RwLock with exclusive write access, returning immediately if it cannot be acquired.