xv6-riscv-kernel/kernel/spinlock.h

53 lines
1 KiB
C
Raw Permalink Normal View History

#pragma once
#include "types.h"
struct spinlock;
// spinlock.c
/**
* Acquire the lock.
* Loops (spins) until the lock is acquired.
* Panics if the lock is already held by this cpu.
*/
void acquire(struct spinlock *);
/**
* Check whether this cpu is holding the lock.
* Interrupts must be off.
*/
int holding(struct spinlock *);
/**
* Initialize spinlock
*/
void initlock(struct spinlock *, char *);
/**
* Release the lock.
* Panics if the lock is not held.
*/
void release(struct spinlock *);
/**
* @brief push_off/pop_off are like intr_off()/intr_on() except that they are matched:
* it takes two pop_off()s to undo two push_off()s. Also, if interrupts
* are initially off, then push_off, pop_off leaves them off.
*/
void push_off(void);
/** @copydoc pop_off */
void pop_off(void);
/** Mutual exclusion spin lock */
struct spinlock {
2024-06-15 16:55:06 +02:00
u32 locked; // Is the lock held?
// NOTE: Perhaps feature gate this?
2006-09-07 16:12:30 +02:00
// For debugging:
2024-06-15 16:55:06 +02:00
char *name; // Name of lock.
struct cpu *cpu; // The cpu holding the lock.
};