Skip to content

Commit

Permalink
fix loom test
Browse files Browse the repository at this point in the history
  • Loading branch information
tglane committed Aug 30, 2024
1 parent 91f3f48 commit 20ca786
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tokio/src/loom/mocked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub(crate) use loom::*;

pub(crate) mod sync {

pub(crate) use loom::sync::MutexGuard;
pub(crate) use loom::sync::{MutexGuard, RwLockReadGuard, RwLockWriteGuard};

#[derive(Debug)]
pub(crate) struct Mutex<T>(loom::sync::Mutex<T>);
Expand Down Expand Up @@ -30,6 +30,38 @@ pub(crate) mod sync {
self.0.get_mut().unwrap()
}
}

#[derive(Debug)]
pub(crate) struct RwLock<T: ?Sized>(loom::sync::RwLock<T>);

#[allow(dead_code)]
impl<T> RwLock<T> {
#[inline]
pub(crate) fn new(t: T) -> Self {
Self(loom::sync::RwLock::new(t))
}

#[inline]
pub(crate) fn read(&self) -> RwLockReadGuard<'_, T> {
self.0.read().unwrap()
}

#[inline]
pub(crate) fn try_read(&self) -> Option<RwLockReadGuard<'_, T>> {
self.0.try_read().ok()
}

#[inline]
pub(crate) fn write(&self) -> RwLockWriteGuard<'_, T> {
self.0.write().unwrap()
}

#[inline]
pub(crate) fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>> {
self.0.try_write().ok()
}
}

pub(crate) use loom::sync::*;

pub(crate) mod atomic {
Expand Down

0 comments on commit 20ca786

Please sign in to comment.