The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
spinlock.c File Reference
#include "kernel/sync/spinlock.h"
#include "arch/arch.h"
#include "kernel/assert.h"
#include "kernel/cpu/cpu.h"
#include "kernel/panic.h"
#include "kernel/memory/tlb.h"

Macros

#define SPIN_LIMIT   (1u << 28)

Functions

void spinlock_init (spinlock_t *lock)
 initialize a spinlock to the unlocked state.
void spin_lock (spinlock_t *lock)
 acquire a lock.
void spin_unlock (spinlock_t *lock)
 release a lock that spin_lock() took.
uint32_t spin_lock_irqsave (spinlock_t *lock)
 mask interrupts on this core, then acquire a lock.
void spin_unlock_irqrestore (spinlock_t *lock, uint32_t flags)
 release a lock and restore the interrupt state captured at acquire time.
bool spin_is_held (const spinlock_t *lock)
 check if the core that runs the call holds a lock.

Macro Definition Documentation

◆ SPIN_LIMIT

#define SPIN_LIMIT   (1u << 28)

Function Documentation

◆ spinlock_init()

void spinlock_init ( spinlock_t * lock)

initialize a spinlock to the unlocked state.

Parameters
lockthe lock to initialize.

◆ spin_lock()

void spin_lock ( spinlock_t * lock)

acquire a lock.

it does not change the interrupt state, so interrupts must be masked already (as in Linux's spin_lock in an IRQ handler). pairs with spin_unlock().

Parameters
lockthe lock to acquire.

◆ spin_unlock()

void spin_unlock ( spinlock_t * lock)

release a lock that spin_lock() took.

it does not change the interrupt state.

Parameters
lockthe lock to release.

◆ spin_lock_irqsave()

uint32_t spin_lock_irqsave ( spinlock_t * lock)

mask interrupts on this core, then acquire a lock.

safe to nest: the returned flags carry whether interrupts were enabled on entry. pairs with spin_unlock_irqrestore().

Parameters
lockthe lock to acquire.
Returns
the interrupt state to hand back to spin_unlock_irqrestore().

◆ spin_unlock_irqrestore()

void spin_unlock_irqrestore ( spinlock_t * lock,
uint32_t flags )

release a lock and restore the interrupt state captured at acquire time.

pairs with spin_lock_irqsave().

Parameters
lockthe lock to release.
flagsthe value returned by spin_lock_irqsave().

◆ spin_is_held()

bool spin_is_held ( const spinlock_t * lock)

check if the core that runs the call holds a lock.

for assertions.

Parameters
lockthe lock to check.
Returns
true if this core holds it.