eqlock(): use separate lock to protect eql, fix missing unlock

This commit is contained in:
cinap_lenrek 2011-08-11 23:02:48 +02:00
parent 4b506cd0ae
commit e9d441fccf
3 changed files with 10 additions and 9 deletions

View file

@ -735,7 +735,8 @@ struct Proc
int trace; /* process being traced? */ int trace; /* process being traced? */
ulong qpc; /* pc calling last blocking qlock */ ulong qpc; /* pc calling last blocking qlock */
QLock *eql; /* interruptable eqlock, protected by rlock */ QLock *eql; /* interruptable eqlock */
Lock eqlock;
int setargs; int setargs;

View file

@ -952,17 +952,18 @@ Pullout:
switch(p->state){ switch(p->state){
case Queueing: case Queueing:
/* Try and pull out of a eqlock */ /* Try and pull out of a eqlock */
lock(&p->rlock); lock(&p->eqlock);
if(p->state == Queueing && p->eql && p->notepending){ if(p->state == Queueing && p->eql && p->notepending){
Proc *d, *l; Proc *d, *l;
QLock *q; QLock *q;
q = p->eql; q = p->eql;
if(!canlock(&q->use)){ if(!canlock(&q->use)){
unlock(&p->rlock); unlock(&p->eqlock);
sched(); sched();
goto Pullout; goto Pullout;
} }
for(l = nil, d = q->head; d; l = d, d = d->qnext) for(l = nil, d = q->head; d; l = d, d = d->qnext)
if(d == p){ if(d == p){
if(l) if(l)
@ -977,9 +978,8 @@ Pullout:
break; break;
} }
unlock(&q->use); unlock(&q->use);
break;
} }
unlock(&p->rlock); unlock(&p->eqlock);
break; break;
case Rendezvous: case Rendezvous:
/* Try and pull out of a rendezvous */ /* Try and pull out of a rendezvous */

View file

@ -54,9 +54,9 @@ eqlock(QLock *q)
up->qpc = getcallerpc(&q); up->qpc = getcallerpc(&q);
up->state = Queueing; up->state = Queueing;
lock(&up->rlock); lock(&up->eqlock);
up->eql = q; up->eql = q;
unlock(&up->rlock); unlock(&up->eqlock);
unlock(&q->use); unlock(&q->use);
@ -129,10 +129,10 @@ qunlock(QLock *q)
p = q->head; p = q->head;
if(p){ if(p){
if(p->eql){ if(p->eql){
lock(&p->rlock); lock(&p->eqlock);
if(p->eql == q) if(p->eql == q)
p->eql = 0; p->eql = 0;
unlock(&p->rlock); unlock(&p->eqlock);
} }
q->head = p->qnext; q->head = p->qnext;
if(q->head == 0) if(q->head == 0)