-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
time: add abstraction for
RwLock
to remove poisoning aspect (#6807)
With #6779 we removed unnecessary allocations from the timerwheel by wrapping it in an `std::sync::RwLock`. Since the `Mutex` used in this part of the project uses an abstraction in `loom::sync::Mutex` to get rid of the poisoning aspects of `std::sync::Mutex` the same should probably be done for the used read-write lock struct. This commit introduces an abstraction to get rid of the poisoning aspects of `std::sync::RwLock` by introducing a wrapper to the `loom::sync` module similar to `loom::sync::Mutex`. Refs: #6779
- Loading branch information
Showing
7 changed files
with
114 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::sync::{self, RwLockReadGuard, RwLockWriteGuard, TryLockError}; | ||
|
||
/// Adapter for `std::sync::RwLock` that removes the poisoning aspects | ||
/// from its api. | ||
#[derive(Debug)] | ||
pub(crate) struct RwLock<T: ?Sized>(sync::RwLock<T>); | ||
|
||
#[allow(dead_code)] | ||
impl<T> RwLock<T> { | ||
#[inline] | ||
pub(crate) fn new(t: T) -> Self { | ||
Self(sync::RwLock::new(t)) | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn read(&self) -> RwLockReadGuard<'_, T> { | ||
match self.0.read() { | ||
Ok(guard) => guard, | ||
Err(p_err) => p_err.into_inner(), | ||
} | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn try_read(&self) -> Option<RwLockReadGuard<'_, T>> { | ||
match self.0.try_read() { | ||
Ok(guard) => Some(guard), | ||
Err(TryLockError::Poisoned(p_err)) => Some(p_err.into_inner()), | ||
Err(TryLockError::WouldBlock) => None, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn write(&self) -> RwLockWriteGuard<'_, T> { | ||
match self.0.write() { | ||
Ok(guard) => guard, | ||
Err(p_err) => p_err.into_inner(), | ||
} | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>> { | ||
match self.0.try_write() { | ||
Ok(guard) => Some(guard), | ||
Err(TryLockError::Poisoned(p_err)) => Some(p_err.into_inner()), | ||
Err(TryLockError::WouldBlock) => None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters