Files
zinnia/include/zinnia/spin.h
T
2026-10-06 01:34:24 +02:00

20 lines
444 B
C

#pragma once
#include <stdatomic.h>
#include <stdint.h>
// Busy-waits in a loop until the lock is freed.
// Does not put the CPU to sleep.
struct spinlock {
_Atomic(uint32_t) owner;
_Atomic(uint32_t) next;
};
void spin_init(struct spinlock* spin);
// Attempts to lock a spinlock. If it's already locked, waits until it's freed.
void spin_lock(struct spinlock* spin);
// Unlocks a spinlock.
void spin_unlock(struct spinlock* spin);