summaryrefslogtreecommitdiff
path: root/spinlock.c
diff options
context:
space:
mode:
authorrtm <rtm>2006-07-12 15:35:33 +0000
committerrtm <rtm>2006-07-12 15:35:33 +0000
commit6eb6f10c5668bc2bdf5e561e0060e7e917ed55c1 (patch)
tree8245cefe266e75ca9836cbde2f86114cb6222fe4 /spinlock.c
parent8148b6ee535b85e97f3b5f3a850b70fdfbbcaf2d (diff)
downloadxv6-labs-6eb6f10c5668bc2bdf5e561e0060e7e917ed55c1.tar.gz
xv6-labs-6eb6f10c5668bc2bdf5e561e0060e7e917ed55c1.tar.bz2
xv6-labs-6eb6f10c5668bc2bdf5e561e0060e7e917ed55c1.zip
passes both usertests
exit had acquire where I meant release swtch now checks that you hold no locks
Diffstat (limited to 'spinlock.c')
-rw-r--r--spinlock.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/spinlock.c b/spinlock.c
index bd6bff5..507e74b 100644
--- a/spinlock.c
+++ b/spinlock.c
@@ -17,10 +17,11 @@ int getcallerpc(void *v) {
void
acquire(struct spinlock * lock)
{
+ struct proc *cp = curproc[cpu()];
unsigned who;
- if(curproc[cpu()])
- who = (unsigned) curproc[cpu()];
+ if(cp)
+ who = (unsigned) cp;
else
who = cpu() + 1;
@@ -38,16 +39,20 @@ acquire(struct spinlock * lock)
lock->who = who;
}
+ if(cp)
+ cp->locks += 1;
+
if(DEBUG) cprintf("cpu%d: acquired at %x\n", cpu(), getcallerpc(&lock));
}
void
release(struct spinlock * lock)
{
+ struct proc *cp = curproc[cpu()];
unsigned who;
- if(curproc[cpu()])
- who = (unsigned) curproc[cpu()];
+ if(cp)
+ who = (unsigned) cp;
else
who = cpu() + 1;
@@ -57,6 +62,8 @@ release(struct spinlock * lock)
panic("release");
lock->count -= 1;
+ if(cp)
+ cp->locks -= 1;
if(lock->count < 1){
lock->who = 0;
cmpxchg(1, 0, &lock->locked);