Skip to main content

ax_kspin/
lib.rs

1#![cfg_attr(not(test), no_std)]
2#![doc = include_str!("../README.md")]
3
4#[cfg(any(test, doctest))]
5extern crate std;
6
7mod base;
8use ax_kernel_guard::{NoOp, NoPreempt, NoPreemptIrqSave};
9#[cfg(feature = "lockdep")]
10pub mod lockdep;
11
12pub use self::base::{BaseSpinLock, BaseSpinLockGuard};
13
14/// Enables or disables the phase-3 lock flow tracing path.
15pub fn set_lockdep_trace_enabled(enabled: bool) {
16    #[cfg(feature = "lockdep")]
17    {
18        ax_lockdep::set_trace_enabled(enabled);
19    }
20
21    #[cfg(not(feature = "lockdep"))]
22    {
23        let _ = enabled;
24    }
25}
26
27/// Dumps the buffered phase-3 trace stream to the raw trace sink.
28pub fn dump_lockdep_trace() {
29    #[cfg(feature = "lockdep")]
30    {
31        ax_lockdep::dump_trace_buffer();
32    }
33}
34
35/// A spin lock that disables kernel preemption while trying to lock, and
36/// re-enables it after unlocking.
37///
38/// It must be used in the local IRQ-disabled context, or never be used in
39/// interrupt handlers.
40pub type SpinNoPreempt<T> = BaseSpinLock<NoPreempt, T>;
41
42/// A guard that provides mutable data access for [`SpinNoPreempt`].
43pub type SpinNoPreemptGuard<'a, T> = BaseSpinLockGuard<'a, NoPreempt, T>;
44
45/// A spin lock that disables kernel preemption and local IRQs while trying to
46/// lock, and re-enables it after unlocking.
47///
48/// It can be used in the IRQ-enabled context.
49pub type SpinNoIrq<T> = BaseSpinLock<NoPreemptIrqSave, T>;
50
51/// A guard that provides mutable data access for [`SpinNoIrq`].
52pub type SpinNoIrqGuard<'a, T> = BaseSpinLockGuard<'a, NoPreemptIrqSave, T>;
53
54/// A raw spin lock that does nothing while trying to lock.
55///
56/// It must be used in the preemption-disabled and local IRQ-disabled context,
57/// or never be used in interrupt handlers.
58pub type SpinRaw<T> = BaseSpinLock<NoOp, T>;
59
60/// A guard that provides mutable data access for [`SpinRaw`].
61pub type SpinRawGuard<'a, T> = BaseSpinLockGuard<'a, NoOp, T>;