Skip to content

Commit

Permalink
Add wrapper around the loom Mutex
Browse files Browse the repository at this point in the history
Signed-off-by: Zahari Dichev <zaharidichev@gmail.com>
  • Loading branch information
zaharidichev committed Sep 24, 2020
1 parent 7149c82 commit 5a7a6a1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tokio/src/loom/mocked.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
pub(crate) use loom::*;

pub(crate) mod sync {

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

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

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

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

#[inline]
pub(crate) fn try_lock(&self) -> Option<MutexGuard<'_, T>> {
self.0.try_lock().ok()
}
}
pub(crate) use loom::sync::*;
}

pub(crate) mod rand {
pub(crate) fn seed() -> u64 {
1
Expand Down

0 comments on commit 5a7a6a1

Please sign in to comment.