use core::ops::DerefMut;
use super::{Mutex, MutexGuard};
use crate::inner::raw::{self, Key};
use crate::lock::{Lock, Wait};
impl<T: ?Sized, L: Lock, Ws: Wait, Wq: Wait> Mutex<T, L, Ws, Wq> {
pub unsafe fn lock_with_local_unchecked<N>(&self, node: Key<N>) -> MutexGuard<'_, T, L, Ws, Wq>
where
N: DerefMut<Target = raw::MutexNode<L>>,
{
if self.lock.try_lock_acquire_weak() {
return MutexGuard::new(self);
}
unsafe {
self.queue.lock_with_local_then_unchecked(node, |()| {
while !self.lock.try_lock_acquire_weak() {
self.lock.wait_lock_relaxed::<Ws>();
}
});
}
MutexGuard::new(self)
}
}