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

1994/0311/port/qio.c (diff list | history)

1994/0309/sys/src/9/port/qio.c:369,3741994/0311/sys/src/9/port/qio.c:369,441 (short | long | prev | next)
1993/0526    
} 
 
1993/0528    
int 
1994/0311    
qpass(Queue *q, Block *b) 
{ 
	int s, i, len; 
	int dowakeup; 
 
	s = splhi(); 
 
	len = BLEN(b); 
 
	/* sync with qread */ 
	dowakeup = 0; 
	lock(q); 
 
	if(q->syncbuf){ 
		/* synchronous communications, just copy into buffer */ 
		if(len < q->synclen) 
			q->synclen = len; 
		i = q->synclen; 
		memmove(q->syncbuf, b->rp, i); 
		q->syncbuf = 0;		/* tell reader buffer is full */ 
		len -= i; 
		if(len <= 0 || (q->state & Qmsg)){ 
			unlock(q); 
			wakeup(&q->rr); 
			ifree(b); 
			splx(s); 
			return i; 
		} 
 
		/* queue anything that's left */ 
		dowakeup = 1; 
		b->rp += i; 
	} 
 
	/* no waiting receivers, room in buffer? */ 
	if(q->len >= q->limit){ 
		unlock(q); 
		splx(s); 
		return -1; 
	} 
 
	/* save in buffer */ 
	if(q->bfirst) 
		q->blast->next = b; 
	else 
		q->bfirst = b; 
	q->blast = b; 
	q->len += len; 
checkb(b, "qproduce"); 
 
	if(q->state & Qstarve){ 
		q->state &= ~Qstarve; 
		dowakeup = 1; 
	} 
	unlock(q); 
 
	if(dowakeup){ 
		if(q->kick) 
			(*q->kick)(q->arg); 
		wakeup(&q->rr); 
	} 
	splx(s); 
 
	return len; 
} 
 
int 
1993/0601    
qproduce(Queue *q, void *vp, int len) 
1993/0526    
{ 
	Block *b; 


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