diff options
author | rtm <rtm> | 2006-07-15 12:03:57 +0000 |
---|---|---|
committer | rtm <rtm> | 2006-07-15 12:03:57 +0000 |
commit | 46bbd72f3eeaff9386b2a90af88f3d46b458a0e8 (patch) | |
tree | 31ca93c160a10c50948329b30d27475aa6b38313 /spinlock.c | |
parent | d9872ffa951291fcc3f7a92c0d235b86435c5714 (diff) | |
download | xv6-labs-46bbd72f3eeaff9386b2a90af88f3d46b458a0e8.tar.gz xv6-labs-46bbd72f3eeaff9386b2a90af88f3d46b458a0e8.tar.bz2 xv6-labs-46bbd72f3eeaff9386b2a90af88f3d46b458a0e8.zip |
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
Diffstat (limited to 'spinlock.c')
-rw-r--r-- | spinlock.c | 58 |
1 files changed, 22 insertions, 36 deletions
@@ -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()]); } |