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