summaryrefslogtreecommitdiff
path: root/spinlock.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-05-31 09:45:59 -0400
committerRobert Morris <[email protected]>2019-05-31 09:45:59 -0400
commit2ec1959fd1016a18ef3b2d154ce7076be8f237e4 (patch)
tree1aa75252085964283b3a2c735771f4da02346517 /spinlock.c
parent0f90388c893d1924e89e2e4d2187eda0004e9d73 (diff)
downloadxv6-labs-2ec1959fd1016a18ef3b2d154ce7076be8f237e4.tar.gz
xv6-labs-2ec1959fd1016a18ef3b2d154ce7076be8f237e4.tar.bz2
xv6-labs-2ec1959fd1016a18ef3b2d154ce7076be8f237e4.zip
fork/wait/exit work
Diffstat (limited to 'spinlock.c')
-rw-r--r--spinlock.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/spinlock.c b/spinlock.c
index 9ee65f6..0377870 100644
--- a/spinlock.c
+++ b/spinlock.c
@@ -1,13 +1,11 @@
// Mutual exclusion spin locks.
#include "types.h"
-#include "defs.h"
#include "param.h"
-#include "x86.h"
#include "memlayout.h"
-#include "mmu.h"
-#include "proc.h"
#include "spinlock.h"
+#include "riscv.h"
+#include "defs.h"
void
initlock(struct spinlock *lk, char *name)
@@ -17,6 +15,27 @@ initlock(struct spinlock *lk, char *name)
lk->cpu = 0;
}
+void
+acquire(struct spinlock *lk)
+{
+ lk->locked = 1;
+ lk->cpu = mycpu();
+}
+
+void
+release(struct spinlock *lk)
+{
+ lk->locked = 0;
+ lk->cpu = 0;
+}
+
+int
+holding(struct spinlock *lk)
+{
+ return lk->locked && lk->cpu == mycpu();
+}
+
+#if 0
// Acquire the lock.
// Loops (spins) until the lock is acquired.
// Holding a lock for a long time may cause
@@ -37,7 +56,7 @@ acquire(struct spinlock *lk)
// references happen after the lock is acquired.
__sync_synchronize();
- // Record info about lock acquisition for debugging.
+ // Record info about lock acquisition for holding() and debugging.
lk->cpu = mycpu();
getcallerpcs(&lk, lk->pcs);
}
@@ -87,11 +106,11 @@ getcallerpcs(void *v, uint64 pcs[])
// Check whether this cpu is holding the lock.
int
-holding(struct spinlock *lock)
+holding(struct spinlock *lk)
{
int r;
pushcli();
- r = lock->locked && lock->cpu == mycpu();
+ r = lk->locked && lk->cpu == mycpu();
popcli();
return r;
}
@@ -123,4 +142,4 @@ popcli(void)
if(mycpu()->ncli == 0 && mycpu()->intena)
sti();
}
-
+#endif