plan 9 kernel history: overview | file list | diff list

1991/0727/port/qlock.c (diff list | history)

port/qlock.c on 1991/0428
1991/0428    
#include "u.h" 
#include "lib.h" 
#include "mem.h" 
#include "dat.h" 
#include "fns.h" 
 
 
void 
qlock(QLock *q) 
{ 
	Proc *p; 
 
1991/0705    
	if(canlock(&q->use)) 
1991/0428    
		return; 
	lock(&q->queue); 
	if(canlock(&q->use)){ 
		unlock(&q->queue); 
		return; 
	} 
1991/0711    
	if(u == 0) 
		panic("qlock"); 
1991/0428    
	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; 
/*	u->p->qlock = q;	/* DEBUG */ 
	unlock(&q->queue); 
	sched(); 
} 
 
int 
canqlock(QLock *q) 
{ 
	return canlock(&q->use); 
} 
 
void 
qunlock(QLock *q) 
{ 
	Proc *p; 
 
	lock(&q->queue); 
/*	u->p->qlock = 0; /* DEBUG */ 
	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); 
	} 
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)