| plan 9 kernel history: overview | file list | diff list |
1998/0604/port/taslock.c (diff list | history)
| port/taslock.c on 1992/0222 | ||
| 1992/0222 | #include "u.h" | |
| 1992/0321 | #include "../port/lib.h" | |
| 1992/0222 | #include "mem.h" #include "dat.h" #include "fns.h" #include "../port/error.h" void | |
| 1995/1030 | lockloop(Lock *l, ulong pc) { print("lock loop key 0x%lux pc 0x%lux held by pc 0x%lux proc %d\n", | |
| 1998/0604 | l->key, pc, l->pc, l->p ? l->p->pid : 0); | |
| 1995/1030 | dumpaproc(up); | |
| 1996/0523 | ||
| 1998/0604 | if(up && up->state == Running && islo()) | |
| 1996/0523 | sched(); | |
| 1995/1030 | } void | |
| 1992/0222 | lock(Lock *l) { | |
| 1996/0523 | int i; | |
| 1998/0604 | ulong pc; | |
| 1995/1009 | pc = getcallerpc(l); | |
| 1996/0522 | if(tas(&l->key) == 0){ l->pc = pc; | |
| 1998/0604 | l->p = up; l->isilock = 0; if(up){ l->pri = up->priority; up->priority = PriLock; } | |
| 1995/0110 | return; | |
| 1995/1009 | } | |
| 1995/0108 | ||
| 1996/0522 | for(;;){ i = 0; | |
| 1998/0604 | while(l->key){ if(conf.nmach < 2){ if(i++ > 1000){ i = 0; lockloop(l, pc); } sched(); } else { if(i++ > 100000000){ i = 0; lockloop(l, pc); } | |
| 1996/0522 | } | |
| 1998/0604 | } | |
| 1995/1009 | if(tas(&l->key) == 0){ l->pc = pc; | |
| 1998/0604 | l->p = up; l->isilock = 0; if(up){ l->pri = up->priority; up->priority = PriLock; } | |
| 1995/0108 | return; | |
| 1995/1009 | } | |
| 1995/0108 | } | |
| 1995/0110 | } | |
| 1995/0108 | ||
| 1995/0110 | void ilock(Lock *l) { ulong x; | |
| 1998/0604 | ulong pc; | |
| 1995/0110 | ||
| 1995/1009 | pc = getcallerpc(l); | |
| 1995/0110 | x = splhi(); if(tas(&l->key) == 0){ l->sr = x; | |
| 1995/1009 | l->pc = pc; | |
| 1998/0604 | l->p = up; l->isilock = 1; | |
| 1993/1204 | return; | |
| 1995/0110 | } | |
| 1998/0522 | if(conf.nmach < 2) panic("ilock: no way out: pc %uX\n", pc); | |
| 1993/0830 | for(;;){ | |
| 1998/0228 | splx(x); | |
| 1994/0808 | while(l->key) ; | |
| 1998/0228 | x = splhi(); | |
| 1995/0110 | if(tas(&l->key) == 0){ l->sr = x; | |
| 1995/1009 | l->pc = pc; | |
| 1998/0604 | l->p = up; l->isilock = 1; | |
| 1992/0222 | return; | |
| 1995/0110 | } | |
| 1992/0222 | } } | |
| 1995/0109 | int canlock(Lock *l) | |
| 1994/0322 | { | |
| 1996/0522 | if(tas(&l->key)) | |
| 1996/0511 | return 0; | |
| 1996/0522 | l->pc = getcallerpc(l); | |
| 1998/0604 | l->p = up; l->isilock = 0; if(up){ l->pri = up->priority; up->priority = PriLock; } | |
| 1992/0222 | return 1; } void unlock(Lock *l) { | |
| 1998/0604 | int p; p = l->pri; | |
| 1998/0522 | if(l->key == 0) print("unlock: not locked: pc %uX\n", getcallerpc(l)); | |
| 1998/0604 | if(l->isilock) print("iunlock of lock: pc %lux, held by %lux\n", getcallerpc(l), l->pc); | |
| 1996/0522 | l->pc = 0; | |
| 1997/0327 | l->key = 0; | |
| 1998/0604 | if(up && p < up->priority) up->priority = p; | |
| 1997/0220 | coherence(); | |
| 1994/0322 | } void iunlock(Lock *l) { ulong sr; | |
| 1998/0603 | if(l->key == 0) print("iunlock: not locked: pc %uX\n", getcallerpc(l)); | |
| 1998/0604 | if(!l->isilock) print("unlock of ilock: pc %lux, held by %lux\n", getcallerpc(l), l->pc); | |
| 1998/0603 | ||
| 1994/0322 | sr = l->sr; | |
| 1995/1014 | l->pc = 0; | |
| 1997/0327 | l->key = 0; | |
| 1994/0322 | splx(sr); | |
| 1997/0220 | coherence(); | |
| 1992/0222 | } | |