From 46bbd72f3eeaff9386b2a90af88f3d46b458a0e8 Mon Sep 17 00:00:00 2001 From: rtm Date: Sat, 15 Jul 2006 12:03:57 +0000 Subject: no more recursive locks wakeup1() assumes you hold proc_table_lock sleep(chan, lock) provides atomic sleep-and-release to wait for condition ugly code in swtch/scheduler to implement new sleep fix lots of bugs in pipes, wait, and exit fix bugs if timer interrupt goes off in schedule() console locks per line, not per byte --- spinlock.c | 58 ++++++++++++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 36 deletions(-) (limited to 'spinlock.c') diff --git a/spinlock.c b/spinlock.c index 507e74b..4c11064 100644 --- a/spinlock.c +++ b/spinlock.c @@ -8,36 +8,20 @@ #define DEBUG 0 -extern use_printf_lock; +extern int use_console_lock; int getcallerpc(void *v) { return ((int*)v)[-1]; } void -acquire(struct spinlock * lock) +acquire1(struct spinlock * lock, struct proc *cp) { - struct proc *cp = curproc[cpu()]; - unsigned who; - - if(cp) - who = (unsigned) cp; - else - who = cpu() + 1; - if(DEBUG) cprintf("cpu%d: acquiring at %x\n", cpu(), getcallerpc(&lock)); - if (lock->who == who && lock->locked){ - lock->count += 1; - } else { - cli(); - // if we get the lock, eax will be zero - // if we don't get the lock, eax will be one - while ( cmpxchg(0, 1, &lock->locked) == 1 ) { ; } - lock->locker_pc = getcallerpc(&lock); - lock->count = 1; - lock->who = who; - } + cli(); + while ( cmpxchg(0, 1, &lock->locked) == 1 ) { ; } + lock->locker_pc = getcallerpc(&lock); if(cp) cp->locks += 1; @@ -46,27 +30,29 @@ acquire(struct spinlock * lock) } void -release(struct spinlock * lock) +release1(struct spinlock * lock, struct proc *cp) { - struct proc *cp = curproc[cpu()]; - unsigned who; - - if(cp) - who = (unsigned) cp; - else - who = cpu() + 1; if(DEBUG) cprintf ("cpu%d: releasing at %x\n", cpu(), getcallerpc(&lock)); - if(lock->who != who || lock->count < 1 || lock->locked != 1) + if(lock->locked != 1) panic("release"); - lock->count -= 1; if(cp) cp->locks -= 1; - if(lock->count < 1){ - lock->who = 0; - cmpxchg(1, 0, &lock->locked); - sti(); - } + + cmpxchg(1, 0, &lock->locked); + sti(); +} + +void +acquire(struct spinlock *lock) +{ + acquire1(lock, curproc[cpu()]); +} + +void +release(struct spinlock *lock) +{ + release1(lock, curproc[cpu()]); } -- cgit v1.2.3