File tree 2 files changed +66
-0
lines changed
2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Sleeping locks
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 = proc -> 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 ;
51
+ release (& lk -> lk );
52
+ return r ;
53
+ }
54
+
55
+
56
+
Original file line number Diff line number Diff line change
1
+ // Long-term locks for processes
2
+ struct sleeplock {
3
+ uint locked ; // Is the lock held?
4
+ struct spinlock lk ; // spinlock protecting this sleep lock
5
+
6
+ // For debugging:
7
+ char * name ; // Name of lock.
8
+ int pid ; // Process holding lock
9
+ };
10
+
You can’t perform that action at this time.
0 commit comments