2016-09-12 01:01:24 +00:00
|
|
|
// Sleeping locks
|
|
|
|
|
|
|
|
#include "types.h"
|
2019-05-31 15:45:42 +00:00
|
|
|
#include "riscv.h"
|
2016-09-12 01:01:24 +00:00
|
|
|
#include "defs.h"
|
|
|
|
#include "param.h"
|
|
|
|
#include "memlayout.h"
|
|
|
|
#include "spinlock.h"
|
2019-07-02 13:14:47 +00:00
|
|
|
#include "proc.h"
|
2016-09-12 01:01:24 +00:00
|
|
|
#include "sleeplock.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
initsleeplock(struct sleeplock *lk, char *name)
|
|
|
|
{
|
|
|
|
initlock(&lk->lk, "sleep lock");
|
|
|
|
lk->name = name;
|
|
|
|
lk->locked = 0;
|
|
|
|
lk->pid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
acquiresleep(struct sleeplock *lk)
|
|
|
|
{
|
|
|
|
acquire(&lk->lk);
|
|
|
|
while (lk->locked) {
|
|
|
|
sleep(lk, &lk->lk);
|
|
|
|
}
|
|
|
|
lk->locked = 1;
|
2017-01-31 22:47:16 +00:00
|
|
|
lk->pid = myproc()->pid;
|
2016-09-12 01:01:24 +00:00
|
|
|
release(&lk->lk);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
releasesleep(struct sleeplock *lk)
|
|
|
|
{
|
|
|
|
acquire(&lk->lk);
|
|
|
|
lk->locked = 0;
|
|
|
|
lk->pid = 0;
|
|
|
|
wakeup(lk);
|
|
|
|
release(&lk->lk);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
holdingsleep(struct sleeplock *lk)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
acquire(&lk->lk);
|
2018-08-30 15:57:46 +00:00
|
|
|
r = lk->locked && (lk->pid == myproc()->pid);
|
2016-09-12 01:01:24 +00:00
|
|
|
release(&lk->lk);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|