summaryrefslogtreecommitdiff
path: root/spinlock.c
diff options
context:
space:
mode:
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);