Branch out the spinlock code into its own header
This commit is contained in:
parent
20551ae040
commit
5a3fa8f6af
2 changed files with 41 additions and 9 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "riscv.h"
|
#include "riscv.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "spinlock.h"
|
||||||
|
|
||||||
struct buf;
|
struct buf;
|
||||||
struct context;
|
struct context;
|
||||||
|
@ -9,7 +10,6 @@ struct file;
|
||||||
struct inode;
|
struct inode;
|
||||||
struct pipe;
|
struct pipe;
|
||||||
struct proc;
|
struct proc;
|
||||||
struct spinlock;
|
|
||||||
struct sleeplock;
|
struct sleeplock;
|
||||||
struct stat;
|
struct stat;
|
||||||
struct superblock;
|
struct superblock;
|
||||||
|
@ -139,14 +139,6 @@ void procdump(void);
|
||||||
// swtch.S
|
// swtch.S
|
||||||
void swtch(struct context *, struct context *);
|
void swtch(struct context *, struct context *);
|
||||||
|
|
||||||
// spinlock.c
|
|
||||||
void acquire(struct spinlock *);
|
|
||||||
int holding(struct spinlock *);
|
|
||||||
void initlock(struct spinlock *, char *);
|
|
||||||
void release(struct spinlock *);
|
|
||||||
void push_off(void);
|
|
||||||
void pop_off(void);
|
|
||||||
|
|
||||||
// sleeplock.c
|
// sleeplock.c
|
||||||
void acquiresleep(struct sleeplock *);
|
void acquiresleep(struct sleeplock *);
|
||||||
void releasesleep(struct sleeplock *);
|
void releasesleep(struct sleeplock *);
|
||||||
|
|
|
@ -2,10 +2,50 @@
|
||||||
|
|
||||||
#include "types.h"
|
#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 */
|
/** Mutual exclusion spin lock */
|
||||||
struct spinlock {
|
struct spinlock {
|
||||||
u32 locked; // Is the lock held?
|
u32 locked; // Is the lock held?
|
||||||
|
|
||||||
|
// NOTE: Perhaps feature gate this?
|
||||||
|
|
||||||
// For debugging:
|
// For debugging:
|
||||||
char *name; // Name of lock.
|
char *name; // Name of lock.
|
||||||
struct cpu *cpu; // The cpu holding the lock.
|
struct cpu *cpu; // The cpu holding the lock.
|
||||||
|
|
Loading…
Reference in a new issue