neptune/kern/libkern/spinlock.h
2025-09-01 23:41:11 +02:00

22 lines
453 B
C

#ifndef KERNEL_Spinlock_H
#define KERNEL_Spinlock_H
#include <proc.h>
#include <stdbool.h>
#include <stdint.h>
typedef struct {
volatile uint32_t v; // 0 = unlocked, 1 = locked
Cpu *cpu;
} spinlock_t;
uint32_t push_off(void);
uint32_t pop_off(void);
void spinlock_init(spinlock_t *l);
bool spin_trylock(spinlock_t *l);
void spin_unlock(spinlock_t *l);
bool spin_is_holding(spinlock_t *l);
void spin_lock(spinlock_t *l);
#endif