| plan 9 kernel history: overview | file list | diff list |
1991/0311/gnot/lock.c (diff list | history)
| gnot/lock.c on 1990/03091 | ||
| 1990/03091 | #include "u.h" #include "lib.h" #include "mem.h" #include "dat.h" #include "fns.h" | |
| 1990/0617 | #define PCOFF -1 | |
| 1990/0403 | /* * N.B. Ken's compiler generates a TAS instruction for the sequence: * * if(l->key >= 0){ * l->key |= 0x80; * ... | |
| 1990/0601 | * * DO NOT TAKE THE ADDRESS OF l->key or the TAS will disappear. | |
| 1990/0403 | */ | |
| 1990/03091 | void lock(Lock *l) { | |
| 1990/1226 | Lock *ll = l; /* do NOT take the address of ll */ | |
| 1990/03091 | int i; /* * Try the fast grab first */ | |
| 1990/0705 | if(ll->key >= 0){ ll->key |= 0x80; ll->pc = ((ulong*)&l)[PCOFF]; | |
| 1990/03091 | return; } for(i=0; i<10000000; i++) | |
| 1990/0705 | if(ll->key >= 0){ ll->key |= 0x80; ll->pc = ((ulong*)&l)[PCOFF]; | |
| 1990/03091 | return; | |
| 1990/0601 | } | |
| 1990/0705 | ll->key = 0; | |
| 1991/0109 | print("lock loop %lux pc %lux held by pc %lux\n", l, ((ulong*)&l)[PCOFF], l->pc); | |
| 1990/03091 | } int canlock(Lock *l) { | |
| 1990/1226 | Lock *ll = l; /* do NOT take the address of ll */ | |
| 1990/0705 | if(ll->key >= 0){ ll->key |= 0x80; ll->pc = ((ulong*)&l)[PCOFF]; | |
| 1990/03091 | return 1; } return 0; } void unlock(Lock *l) { l->pc = 0; | |
| 1990/0403 | l->key = 0; | |
| 1990/03091 | } void qlock(QLock *q) { Proc *p; if(canlock(&q->use)) return; lock(&q->queue); if(canlock(&q->use)){ unlock(&q->queue); return; } p = q->tail; if(p == 0) q->head = u->p; else p->qnext = u->p; q->tail = u->p; u->p->qnext = 0; u->p->state = Queueing; | |
| 1990/05313 | u->p->qlock = q; /* DEBUG */ | |
| 1990/03091 | unlock(&q->queue); sched(); } | |
| 1990/0312 | int canqlock(QLock *q) { return canlock(&q->use); } | |
| 1990/03091 | void qunlock(QLock *q) { Proc *p; lock(&q->queue); | |
| 1991/0311 | if(u) u->p->qlock = 0; | |
| 1990/03091 | if(q->head){ p = q->head; q->head = p->qnext; if(q->head == 0) q->tail = 0; unlock(&q->queue); ready(p); }else{ unlock(&q->use); unlock(&q->queue); } } | |