use std::{future::Future, task::Context};
pub trait Lockable {
type GuardMut<'a>
where
Self: 'a;
fn lock(&self) -> Self::GuardMut<'_>;
fn try_lock(&self) -> Option<Self::GuardMut<'_>>;
fn unlock(guard: Self::GuardMut<'_>) -> &Self;
}
pub trait LockableNew: Lockable {
type Value;
fn new(value: Self::Value) -> Self;
}
pub trait AsyncLockable {
type GuardMut<'a>: AsyncGuardMut<'a, Locker = Self> + Send + Unpin
where
Self: 'a;
type GuardMutFuture<'a>: Future<Output = Self::GuardMut<'a>> + Send
where
Self: 'a;
fn lock(&self) -> Self::GuardMutFuture<'_>;
fn unlock<'a>(guard: Self::GuardMut<'a>) -> &'a Self;
}
pub trait AsyncGuardMut<'a> {
type Locker: AsyncLockable<GuardMut<'a> = Self>
where
Self: 'a;
}
pub trait AsyncLockableMediator {
#[cfg(not(feature = "trace_lock"))]
fn wait_lockable(&mut self, cx: &mut Context<'_>) -> usize;
#[cfg(feature = "trace_lock")]
fn wait_lockable(
&mut self,
cx: &mut Context<'_>,
tracer: &'static std::panic::Location<'static>,
) -> usize;
fn cancel(&mut self, key: usize) -> bool;
#[cfg(feature = "trace_lock")]
fn notify_one(&mut self, id: usize, tracer: &'static std::panic::Location<'static>);
#[cfg(not(feature = "trace_lock"))]
fn notify_one(&mut self);
fn notify_all(&mut self);
}