Skip to main content

Module spinlock

Module spinlock 

Source
Expand description

Generic spinlock with configurable guard behaviour.

§Choosing a guardian

SpinLock<T>                  →  SpinLock<T, IrqDisabled>   (default)
SpinLock<T, IrqDisabled>     →  saves RFLAGS + clears IF (equiv. spin_lock_irqsave)
SpinLock<T, PreemptDisabled> →  disables preemption only, IRQs untouched

Use IrqDisabled (the default) for:

  • Data shared across CPUs (heap, VFS, IPC queues, network rings, …)
  • Any data touched from interrupt handlers

Use PreemptDisabled for:

  • Per-CPU data never accessed from interrupt handlers (scheduler run-queues, per-CPU frame caches, statistics counters …)

All call sites that use SpinLock<T> without a type argument continue to compile unchanged : IrqDisabled is the default guardian.

§Debug helpers

debug_set_watch_lock_addr / debug_clear_watch_lock_addr emit a serial trace on every drop of a specific lock instance : useful when hunting deadlocks.

Structs§

SpinLock
A spinlock parameterised by a Guardian.
SpinLockGuard
RAII guard that holds the lock and carries the guardian state.

Constants§

DEBUG_TRACE_WATCH_SLOTS 🔒
Maximum number of locks that can be traced simultaneously via E9 port.

Statics§

DEBUG_TRACE_WATCH_ADDRS 🔒
Fixed-size array of watched lock addresses for E9 trace. Each slot emits a unique ASCII tag (‘A’..‘H’) on acquire/release.
DEBUG_WATCH_LOCK_ADDR 🔒

Functions§

debug_clear_trace_slot
Clear a specific trace slot by index.
debug_clear_watch_lock_addr
Clear the watched lock address.
debug_set_trace_buddy_addr
Legacy alias: register the first available trace slot.
debug_set_trace_lock_addr
Register a lock address for E9 trace. Returns the slot index (0..7), or None if all slots are in use.
debug_set_trace_slab_addr
Legacy alias: register the first available trace slot.
debug_set_watch_lock_addr
Register a lock address to trace on every drop (serial console output).
emit_trace_e9 🔒
Emit an E9 byte for each matching trace slot (acquire = uppercase, release = lowercase).