22 lines
453 B
C
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
|