Skip to content

Commit ac4c959

Browse files
authored
sync: fix implementation of unused RwLock::try_* methods (#7587)
bd4ccae 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 <mgrigorov@apache.org>
1 parent 14e739c commit ac4c959

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tokio/src/loom/std/parking_lot.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use std::fmt;
77
use std::marker::PhantomData;
88
use std::ops::{Deref, DerefMut};
9-
use std::sync::LockResult;
9+
use std::sync::{LockResult, TryLockError};
1010
use std::time::Duration;
1111

1212
// All types in this file are marked with PhantomData to ensure that
@@ -101,15 +101,19 @@ impl<T> RwLock<T> {
101101
}
102102

103103
pub(crate) fn try_read(&self) -> Option<RwLockReadGuard<'_, T>> {
104-
Some(RwLockReadGuard(PhantomData, self.1.read()))
104+
self.1
105+
.try_read()
106+
.map(|guard| RwLockReadGuard(PhantomData, guard))
105107
}
106108

107109
pub(crate) fn write(&self) -> RwLockWriteGuard<'_, T> {
108110
RwLockWriteGuard(PhantomData, self.1.write())
109111
}
110112

111113
pub(crate) fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>> {
112-
Some(RwLockWriteGuard(PhantomData, self.1.write()))
114+
self.1
115+
.try_write()
116+
.map(|guard| RwLockWriteGuard(PhantomData, guard))
113117
}
114118
}
115119

0 commit comments

Comments
 (0)