kspin/lib.rs
1#![cfg_attr(not(test), no_std)]
2#![doc = include_str!("../README.md")]
3
4mod base;
5
6use kernel_guard::{NoOp, NoPreempt, NoPreemptIrqSave};
7
8pub use self::base::{BaseSpinLock, BaseSpinLockGuard};
9
10/// A spin lock that disables kernel preemption while trying to lock, and
11/// re-enables it after unlocking.
12///
13/// It must be used in the local IRQ-disabled context, or never be used in
14/// interrupt handlers.
15pub type SpinNoPreempt<T> = BaseSpinLock<NoPreempt, T>;
16
17/// A guard that provides mutable data access for [`SpinNoPreempt`].
18pub type SpinNoPreemptGuard<'a, T> = BaseSpinLockGuard<'a, NoPreempt, T>;
19
20/// A spin lock that disables kernel preemption and local IRQs while trying to
21/// lock, and re-enables it after unlocking.
22///
23/// It can be used in the IRQ-enabled context.
24pub type SpinNoIrq<T> = BaseSpinLock<NoPreemptIrqSave, T>;
25
26/// A guard that provides mutable data access for [`SpinNoIrq`].
27pub type SpinNoIrqGuard<'a, T> = BaseSpinLockGuard<'a, NoPreemptIrqSave, T>;
28
29/// A raw spin lock that does nothing while trying to lock.
30///
31/// It must be used in the preemption-disabled and local IRQ-disabled context,
32/// or never be used in interrupt handlers.
33pub type SpinRaw<T> = BaseSpinLock<NoOp, T>;
34
35/// A guard that provides mutable data access for [`SpinRaw`].
36pub type SpinRawGuard<'a, T> = BaseSpinLockGuard<'a, NoOp, T>;