pub(crate) use ax_fs_ng::os::sync::SleepMutex as FsMutex;
pub(crate) use ax_runtime::sync::*;
#[repr(transparent)]
pub struct IrqMutex<T: ?Sized>(ax_runtime::sync::SpinLock<T>);
pub(crate) type IrqMutexGuard<'a, T> = ax_runtime::sync::SpinLockIrqSaveGuard<'a, T>;
impl<T> IrqMutex<T> {
#[track_caller]
pub(crate) const fn new(value: T) -> Self {
Self(ax_runtime::sync::SpinLock::new(value))
}
#[track_caller]
pub(crate) fn lock(&self) -> IrqMutexGuard<'_, T> {
self.0.lock_irqsave()
}
#[track_caller]
pub(crate) fn lock_nested(&self, subclass: u32) -> IrqMutexGuard<'_, T> {
self.0.lock_irqsave_nested(subclass)
}
#[track_caller]
pub(crate) fn try_lock(&self) -> Option<IrqMutexGuard<'_, T>> {
self.0.try_lock_irqsave()
}
}
impl<T: Default> Default for IrqMutex<T> {
fn default() -> Self {
Self::new(T::default())
}
}
impl<T: core::fmt::Debug> core::fmt::Debug for IrqMutex<T> {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.0.fmt(formatter)
}
}
pub(crate) type NoPreemptMutex<T> = SpinLock<T>;
pub(crate) type RawSpinNoIrq = RawIrqSaveMutex;
pub(crate) type RwLock<T> = SpinRwLock<T>;
pub(crate) struct ContextSwitchRwLock<T: ?Sized>(SpinRwLock<T>);
impl<T> ContextSwitchRwLock<T> {
pub(crate) const fn new(value: T) -> Self {
Self(SpinRwLock::new(value))
}
}
impl<T: ?Sized> ContextSwitchRwLock<T> {
#[track_caller]
pub(crate) fn read(&self) -> SpinRwLockReadGuard<'_, T> {
self.0.read()
}
#[track_caller]
pub(crate) fn write(&self) -> SpinRwLockWriteGuard<'_, T> {
self.0.write()
}
#[track_caller]
pub(crate) unsafe fn read_for_context_switch(&self) -> RawSpinRwLockReadGuard<'_, T> {
unsafe { self.0.read_raw() }
}
pub(crate) unsafe fn release_context_switch_reader(&self) {
unsafe { self.0.force_read_decrement_raw() };
}
}