use std::time::Duration;
pub(crate) use loom::sync::MutexGuard;
pub(crate) struct Mutex<T>(loom::sync::Mutex<T>);
impl<T> Mutex<T> {
pub(crate) fn new(val: T) -> Self {
Self(loom::sync::Mutex::new(val))
}
pub(crate) fn lock(&self) -> MutexGuard<'_, T> {
self.0.lock().unwrap()
}
}
pub(crate) struct Condvar(loom::sync::Condvar);
impl Condvar {
pub(crate) fn new() -> Self {
Self(loom::sync::Condvar::new())
}
pub(crate) fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> MutexGuard<'a, T> {
self.0.wait(guard).unwrap()
}
pub(crate) fn wait_timeout<'a, T>(
&self,
guard: MutexGuard<'a, T>,
timeout: Duration,
) -> (MutexGuard<'a, T>, bool) {
let (guard, result) = self.0.wait_timeout(guard, timeout).unwrap();
(guard, result.timed_out())
}
pub(crate) fn notify_one(&self) {
self.0.notify_one();
}
pub(crate) fn notify_all(&self) {
self.0.notify_all();
}
}
pub(crate) mod cell {
pub(crate) use loom::cell::UnsafeCell;
}
pub(crate) mod sync {
pub(crate) use loom::sync::Arc;
pub(crate) use super::{Condvar, Mutex, MutexGuard};
pub(crate) mod atomic {
pub(crate) use loom::sync::atomic::{
AtomicBool, AtomicPtr, AtomicU64, AtomicU8, AtomicUsize, Ordering,
};
}
}
pub(crate) mod thread {
pub(crate) use loom::thread::{current, spawn, yield_now, Builder, JoinHandle};
}