mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
sync: fix implementation of unused RwLock::try_* methods (#7587)
bd4ccae184 introduced a wrapper for the
RwLock to get rid of poisoning aspects.
By mistake (?!) its try_read/write methods actually delegate to
read/write() and this would lead to blocking
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::sync::LockResult;
|
||||
use std::sync::{LockResult, TryLockError};
|
||||
use std::time::Duration;
|
||||
|
||||
// All types in this file are marked with PhantomData to ensure that
|
||||
@@ -101,7 +101,9 @@ impl<T> RwLock<T> {
|
||||
}
|
||||
|
||||
pub(crate) fn try_read(&self) -> Option<RwLockReadGuard<'_, T>> {
|
||||
Some(RwLockReadGuard(PhantomData, self.1.read()))
|
||||
self.1
|
||||
.try_read()
|
||||
.map(|guard| RwLockReadGuard(PhantomData, guard))
|
||||
}
|
||||
|
||||
pub(crate) fn write(&self) -> RwLockWriteGuard<'_, T> {
|
||||
@@ -109,7 +111,9 @@ impl<T> RwLock<T> {
|
||||
}
|
||||
|
||||
pub(crate) fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>> {
|
||||
Some(RwLockWriteGuard(PhantomData, self.1.write()))
|
||||
self.1
|
||||
.try_write()
|
||||
.map(|guard| RwLockWriteGuard(PhantomData, guard))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user