This source file includes following definitions.
- initsleeplock
- acquiresleep
- releasesleep
- holdingsleep
1
2
3 #include "types.h"
4 #include "riscv.h"
5 #include "defs.h"
6 #include "param.h"
7 #include "memlayout.h"
8 #include "spinlock.h"
9 #include "proc.h"
10 #include "sleeplock.h"
11
12 void
13 initsleeplock(struct sleeplock *lk, char *name)
14 {
15 initlock(&lk->lk, "sleep lock");
16 lk->name = name;
17 lk->locked = 0;
18 lk->pid = 0;
19 }
20
21 void
22 acquiresleep(struct sleeplock *lk)
23 {
24 acquire(&lk->lk);
25 while (lk->locked) {
26 sleep(lk, &lk->lk);
27 }
28 lk->locked = 1;
29 lk->pid = myproc()->pid;
30 release(&lk->lk);
31 }
32
33 void
34 releasesleep(struct sleeplock *lk)
35 {
36 acquire(&lk->lk);
37 lk->locked = 0;
38 lk->pid = 0;
39 wakeup(lk);
40 release(&lk->lk);
41 }
42
43 int
44 holdingsleep(struct sleeplock *lk)
45 {
46 int r;
47
48 acquire(&lk->lk);
49 r = lk->locked && (lk->pid == myproc()->pid);
50 release(&lk->lk);
51 return r;
52 }
53
54
55