miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
Ticket Spinlock

FIFO ticket spinlock with IRQ-safe variants. More...

Classes

struct  spinlock_t

Macros

#define SPINLOCK_INIT   { .counter = 0 }

Functions

void spinlock_lock (spinlock_t *lock)
void spinlock_unlock (spinlock_t *lock)
void spinlock_irqsave (spinlock_t *lock, unsigned long *flags)
void spinlock_irqrestore (spinlock_t *lock, unsigned long flags)
void spinlock_irq (spinlock_t *lock)
void spinlock_irq_unlock (spinlock_t *lock)

Detailed Description

FIFO ticket spinlock with IRQ-safe variants.

Provides a 16-bit ticket spinlock (spinlock_t) and four operations:

  • spinlock_lock / spinlock_unlock: basic acquire/release (no IRQ management).
  • spinlock_irqsave / spinlock_irqrestore: IRQ-safe variants using RFLAGS save.
  • spinlock_irq / spinlock_irq_unlock: unconditional cli/sti variants.

Macro Definition Documentation

◆ SPINLOCK_INIT

#define SPINLOCK_INIT   { .counter = 0 }

SPINLOCK_INIT — static initialiser; produces a free (unlocked) spinlock.

Function Documentation

◆ spinlock_irq()

void spinlock_irq ( spinlock_t * lock)

spinlock_irq() - Unconditionally disable IRQs then acquire spinlock. @lock: Spinlock to acquire.

Use only when caller is certain IRQs were enabled (no RFLAGS save needed). Paired with spinlock_irq_unlock().

Here is the call graph for this function:

◆ spinlock_irq_unlock()

void spinlock_irq_unlock ( spinlock_t * lock)

spinlock_irq_unlock() - Release spinlock and unconditionally re-enable IRQs. @lock: Spinlock to release. Must have been acquired via spinlock_irq().

Here is the call graph for this function:

◆ spinlock_irqrestore()

void spinlock_irqrestore ( spinlock_t * lock,
unsigned long flags )

spinlock_irqrestore() - Release spinlock and restore interrupt state. @lock: Spinlock to release. Must have been acquired via spinlock_irqsave. @flags: Saved RFLAGS from spinlock_irqsave (restored as-is; re-enables IRQs if they were enabled before the matching spinlock_irqsave call).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spinlock_irqsave()

void spinlock_irqsave ( spinlock_t * lock,
unsigned long * flags )

spinlock_irqsave() - Save interrupt state, disable IRQs, then acquire. @lock: Spinlock to acquire. @flags: Output — saved RFLAGS value (pass to spinlock_irqrestore).

Use in any code path reachable from both normal context and LAPIC timer ISR. Prevents ISR re-entering the same lock while the lock is held.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spinlock_lock()

void spinlock_lock ( spinlock_t * lock)

spinlock_lock() - Acquire the spinlock (spin until free). @lock: Spinlock to acquire.

Atomically claims a ticket (incrementing next) and spins with PAUSE hint until owner reaches that ticket. FIFO order guaranteed. Do NOT call from ISR context (use spinlock_irqsave instead).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spinlock_unlock()

void spinlock_unlock ( spinlock_t * lock)

spinlock_unlock() - Release the spinlock. @lock: Spinlock to release. Must be held by the calling CPU.

Atomically increments the owner field, handing the lock to the next waiter.

Here is the call graph for this function:
Here is the caller graph for this function: