#[cfg(all(feature = "pthread", unix))]
pub use super::pthread::PthreadMutex;
pub use super::spin::SpinMutex;
pub unsafe trait Mutex: Send + Sync + 'static {
const INIT: Self;
#[doc(hidden)]
fn new() -> Self
where
Self: Sized,
{
Self::INIT
}
type Guard<'a>
where
Self: 'a;
fn lock(&self) -> Self::Guard<'_>;
unsafe fn unlock<'a>(&'a self, guard: Self::Guard<'a>);
}
#[cfg(feature = "lock_api")]
unsafe impl<R: lock_api::RawMutex + Send + Sync + 'static> Mutex for lock_api::Mutex<R, ()> {
#[allow(clippy::declare_interior_mutable_const)]
const INIT: Self = lock_api::Mutex::new(());
type Guard<'a>
= ()
where
Self: 'a;
#[inline]
fn lock(&self) -> Self::Guard<'_> {
core::mem::forget(lock_api::Mutex::lock(self));
}
#[inline]
unsafe fn unlock<'a>(&'a self, _guard: Self::Guard<'a>) {
unsafe { lock_api::Mutex::force_unlock(self) };
}
}
cfg_if::cfg_if! {
if #[cfg(any(loom, miri))] {
type DefaultMutexImpl = crate::loom::sync::Mutex<()>;
} else if #[cfg(feature = "parking_lot")] {
type DefaultMutexImpl = parking_lot::Mutex<()>;
} else if #[cfg(feature = "std")] {
type DefaultMutexImpl = crate::loom::sync::Mutex<()>;
} else if #[cfg(all(feature = "pthread", unix))] {
type DefaultMutexImpl = PthreadMutex;
} else {
type DefaultMutexImpl = SpinMutex;
}
}
pub type DefaultMutex = DefaultMutexImpl;