Skip to content

Commit 57772b9

Browse files
committed
loom: loom::std::parking_lot::RwLock try_read/try_write methods block
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 86400a1 commit 57772b9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tokio/src/loom/std/parking_lot.rs

Lines changed: 9 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,21 @@ impl<T> RwLock<T> {
101101
}
102102

103103
pub(crate) fn try_read(&self) -> Option<RwLockReadGuard<'_, T>> {
104-
Some(RwLockReadGuard(PhantomData, self.1.read()))
104+
match self.1.try_read() {
105+
Some(guard) => Some(RwLockReadGuard(PhantomData, guard)),
106+
None => None,
107+
}
105108
}
106109

107110
pub(crate) fn write(&self) -> RwLockWriteGuard<'_, T> {
108111
RwLockWriteGuard(PhantomData, self.1.write())
109112
}
110113

111114
pub(crate) fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>> {
112-
Some(RwLockWriteGuard(PhantomData, self.1.write()))
115+
match self.1.try_write() {
116+
Some(guard) => Some(RwLockWriteGuard(PhantomData, guard)),
117+
None => None,
118+
}
113119
}
114120
}
115121

0 commit comments

Comments
 (0)