diff --git a/tokio/src/loom/std/parking_lot.rs b/tokio/src/loom/std/parking_lot.rs index 6a8375b07..9367ae015 100644 --- a/tokio/src/loom/std/parking_lot.rs +++ b/tokio/src/loom/std/parking_lot.rs @@ -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 RwLock { } pub(crate) fn try_read(&self) -> Option> { - 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 RwLock { } pub(crate) fn try_write(&self) -> Option> { - Some(RwLockWriteGuard(PhantomData, self.1.write())) + self.1 + .try_write() + .map(|guard| RwLockWriteGuard(PhantomData, guard)) } }