#[cfg(not(feature = "spin_loop"))]
mod futex;
mod spin_wait;
#[cfg(not(feature = "spin_loop"))]
mod sync;
#[cfg(feature = "spin_loop")]
#[path = "phase_locker/sync_spinning.rs"]
mod sync;
pub(crate) use sync::Mutex;
pub(crate) use sync::{SyncPhaseGuard, SyncPhaseLocker, SyncReadPhaseGuard};
mod unsync;
pub(crate) use unsync::UnSyncPhaseLocker;
pub(crate) use unsync::{UnSyncPhaseGuard, UnSyncReadPhaseGuard};
use super::{Phase, Phased};
pub(crate) unsafe trait PhaseGuard<'a, T: ?Sized + 'a> {
fn set_phase(&mut self, p: Phase);
fn commit_phase(&mut self);
fn phase(&self) -> Phase;
fn transition<R>(
&mut self,
f: impl FnOnce(&'a T) -> R,
on_success: Phase,
on_panic: Phase,
) -> R;
}
pub(crate) trait Mappable<T, V, U> {
fn map<F: FnOnce(&T) -> &V>(self, f: F) -> U;
}
pub(crate) unsafe trait PhaseLocker<'a, T: 'a> {
type ReadGuard: Phased;
type WriteGuard: Phased + PhaseGuard<'a, T>;
fn lock<FL: Fn(Phase) -> LockNature, FW: Fn(Phase) -> LockNature>(
&'a self,
value: &'a T,
lock_nature: FL,
on_wake_nature: FW,
hint: Phase,
) -> LockResult<Self::ReadGuard, Self::WriteGuard>;
fn lock_mut(&'a mut self, value: &'a T) -> Self::WriteGuard;
fn try_lock<F: Fn(Phase) -> LockNature>(
&'a self,
value: &'a T,
lock_nature: F,
hint: Phase,
) -> Option<LockResult<Self::ReadGuard, Self::WriteGuard>>;
fn phase(&self) -> Phase;
}
pub(crate) unsafe trait MutPhaseLocker {
fn get_phase_unique(&mut self) -> Phase;
fn set_phase(&mut self, p: Phase);
fn transition<R>(&mut self, f: impl FnOnce() -> R, on_success: Phase, on_panic: Phase) -> R;
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum LockNature {
Read,
Write,
None,
}
pub enum LockResult<R, W> {
Read(R),
Write(W),
None(Phase),
}
#[cfg(all(feature = "lock_statistics", not(feature = "spin_loop")))]
pub use sync::LockStatistics;