use core::{ops::Range, pin::Pin};
pub mod rbtree;
pub unsafe trait IntervalRwLockCore {
type Index;
type Priority;
type ReadLockState: Default;
type WriteLockState: Default;
type TryReadLockState: Default;
type TryWriteLockState: Default;
type InProgress;
const INIT: Self;
fn lock_read<Callback: LockCallback<Self::InProgress>>(
self: Pin<&mut Self>,
range: Range<Self::Index>,
priority: Self::Priority,
state: Pin<&mut Self::ReadLockState>,
callback: Callback,
) -> Callback::Output;
fn lock_write<Callback: LockCallback<Self::InProgress>>(
self: Pin<&mut Self>,
range: Range<Self::Index>,
priority: Self::Priority,
state: Pin<&mut Self::WriteLockState>,
callback: Callback,
) -> Callback::Output;
fn try_lock_read(
self: Pin<&mut Self>,
range: Range<Self::Index>,
state: Pin<&mut Self::TryReadLockState>,
) -> bool;
fn try_lock_write(
self: Pin<&mut Self>,
range: Range<Self::Index>,
state: Pin<&mut Self::TryWriteLockState>,
) -> bool;
fn unlock_read<Callback: UnlockCallback<Self::InProgress>>(
self: Pin<&mut Self>,
state: Pin<&mut Self::ReadLockState>,
callback: Callback,
) -> Option<Self::InProgress>;
fn unlock_write<Callback: UnlockCallback<Self::InProgress>>(
self: Pin<&mut Self>,
state: Pin<&mut Self::WriteLockState>,
callback: Callback,
) -> Option<Self::InProgress>;
fn unlock_try_read<Callback: UnlockCallback<Self::InProgress>>(
self: Pin<&mut Self>,
state: Pin<&mut Self::TryReadLockState>,
callback: Callback,
);
fn unlock_try_write<Callback: UnlockCallback<Self::InProgress>>(
self: Pin<&mut Self>,
state: Pin<&mut Self::TryWriteLockState>,
callback: Callback,
);
fn inspect_read_mut<'a>(
self: Pin<&'a mut Self>,
state: Pin<&'a mut Self::ReadLockState>,
) -> LockState<&'a mut Self::InProgress>;
fn inspect_write_mut<'a>(
self: Pin<&'a mut Self>,
state: Pin<&'a mut Self::WriteLockState>,
) -> LockState<&'a mut Self::InProgress>;
}
pub trait LockCallback<InProgress> {
type Output;
fn in_progress(self) -> (Self::Output, InProgress);
fn complete(self) -> Self::Output;
}
pub trait UnlockCallback<InProgress> {
fn complete(&mut self, in_progress: InProgress);
}
impl UnlockCallback<!> for () {
fn complete(&mut self, in_progress: !) {
match in_progress {}
}
}
#[derive(Debug, Clone, Copy)]
pub enum LockState<InProgress> {
InProgress(InProgress),
Complete,
}