]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
feat: improve spinlock with per-arch cpu_relax() and memory barriers
authorTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 06:57:43 +0000 (03:57 -0300)
committerTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 06:57:43 +0000 (03:57 -0300)
commit34af0e90e4b877d1d3a1b8ec328849d165523293
treefc5085866ff89d34a38f19ab200a613bb27b1483
parent58188693a547ef8db68eb8016ca8617ce3b56cd3
feat: improve spinlock with per-arch cpu_relax() and memory barriers

Spinlock improvements for SMP readiness:
- Add cpu_relax() with per-arch spin-wait hints:
  x86: PAUSE, ARM/AArch64: YIELD, RISC-V: FENCE, MIPS: PAUSE
- Add __sync_synchronize() barrier before lock release in spin_unlock
- Add spin_is_locked() debug helper
- Add spin_trylock() for non-blocking lock attempts
- TTAS (test-and-test-and-set) pattern with cpu_relax() in inner loop
- __sync_lock_test_and_set maps to XCHG (x86), LDREX/STREX (ARM),
  AMOSWAP.W.AQ (RISC-V), LL/SC (MIPS)

Passes: make, cppcheck, QEMU smoke test.
include/spinlock.h