diff options
author | Robert Morris <[email protected]> | 2019-05-31 09:45:59 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2019-05-31 09:45:59 -0400 |
commit | 2ec1959fd1016a18ef3b2d154ce7076be8f237e4 (patch) | |
tree | 1aa75252085964283b3a2c735771f4da02346517 /spinlock.c | |
parent | 0f90388c893d1924e89e2e4d2187eda0004e9d73 (diff) | |
download | xv6-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.c | 35 |
1 files changed, 27 insertions, 8 deletions
@@ -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 |