diff options
author | rtm <rtm> | 2006-07-12 15:35:33 +0000 |
---|---|---|
committer | rtm <rtm> | 2006-07-12 15:35:33 +0000 |
commit | 6eb6f10c5668bc2bdf5e561e0060e7e917ed55c1 (patch) | |
tree | 8245cefe266e75ca9836cbde2f86114cb6222fe4 /spinlock.c | |
parent | 8148b6ee535b85e97f3b5f3a850b70fdfbbcaf2d (diff) | |
download | xv6-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.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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); |