#[cfg(all(not(feature = "std"), not(feature = "spinlock")))]
type Lock<T> = super::mcs::MCSLock<T>;
#[cfg(all(not(feature = "std"), feature = "spinlock"))]
type Lock<T> = super::spinlock::SpinLock<T>;
#[cfg(all(not(feature = "std"), not(feature = "spinlock")))]
pub type LockGuard<'a, T> = super::mcs::MCSLockGuard<'a, T>;
#[cfg(all(not(feature = "std"), feature = "spinlock"))]
pub type LockGuard<'a, T> = super::spinlock::SpinLockGuard<'a, T>;
#[cfg(feature = "std")]
type Lock<T> = parking_lot::Mutex<T>;
#[cfg(feature = "std")]
pub type LockGuard<'a, T> = parking_lot::MutexGuard<'a, T>;
pub struct Mutex<T: Send> {
#[cfg(not(std))]
mutex: Lock<T>,
}
impl<T: Send> Mutex<T> {
pub const fn new(v: T) -> Self {
Self {
mutex: Lock::new(v),
}
}
#[cfg(all(not(feature = "std"), not(feature = "spinlock")))]
#[inline(always)]
pub fn lock<'a>(&'a self, node: &'a mut MCSNode<T>) -> LockGuard<'a, T> {
self.mutex.lock(node)
}
#[cfg(all(not(feature = "std"), feature = "spinlock"))]
#[inline(always)]
pub fn lock<'a>(&'a self, _node: &'a mut MCSNode<T>) -> LockGuard<'a, T> {
self.mutex.lock()
}
#[cfg(feature = "std")]
#[inline(always)]
pub fn lock<'a>(&'a self, _node: &mut MCSNode<T>) -> LockGuard<'a, T> {
self.mutex.lock()
}
#[cfg(all(not(feature = "std"), not(feature = "spinlock")))]
#[inline(always)]
pub fn try_lock<'a>(&'a self, node: &'a mut MCSNode<T>) -> Option<LockGuard<'a, T>> {
self.mutex.try_lock(node)
}
#[cfg(all(not(feature = "std"), feature = "spinlock"))]
#[inline(always)]
pub fn try_lock<'a>(&'a self, _node: &'a mut MCSNode<T>) -> Option<LockGuard<'a, T>> {
self.mutex.try_lock()
}
#[cfg(feature = "std")]
#[inline(always)]
pub fn try_lock<'a>(&'a self, _node: &mut MCSNode<T>) -> Option<LockGuard<'a, T>> {
self.mutex.try_lock()
}
}
pub use super::mcs::MCSNode;