use kernel_arch::ArchitectureImpl;
use yggdrasil_abi::error::Error;

pub mod fence;
pub mod spin_rwlock;

pub use fence::SpinFence;
pub type IrqSafeSpinlock<T> = kernel_arch::sync::IrqSafeSpinlock<ArchitectureImpl, T>;
pub type IrqSafeSpinlockGuard<'a, T> =
    kernel_arch::sync::IrqSafeSpinlockGuard<'a, ArchitectureImpl, T>;
pub type IrqGuard = kernel_arch::guard::IrqGuard<ArchitectureImpl>;

pub type Spinlock<T> = kernel_arch::sync::Spinlock<ArchitectureImpl, T>;
pub type SpinlockGuard<'a, T> = kernel_arch::sync::SpinlockGuard<'a, ArchitectureImpl, T>;

pub trait LockMethod<'q> {
    type Guard<'a>
    where
        'a: 'q,
        Self: 'a;

    fn lock(&'q self) -> Result<Self::Guard<'q>, Error>;

    /// # Safety
    ///
    /// Only meant to be called from Guard's [Drop] impl.
    unsafe fn release(&self);
}
