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

1990/0629/port/devpipe.c (diff list | history)

1990/0617/sys/src/9/port/devpipe.c:32,371990/0629/sys/src/9/port/devpipe.c:32,39 (short | long | prev | next)
1990/0227    
pipeattach(char *spec) 
{ 
	Chan *c; 
1990/0629    
	int i; 
 
1990/0227    
	/* 
	 *  make the first stream 
	 */ 
1990/0617/sys/src/9/port/devpipe.c:59,661990/0629/sys/src/9/port/devpipe.c:61,79
1990/0227    
	/* 
	 *  attach it to the first 
	 */ 
1990/0629    
	c->stream->devq->ptr = (Stream *)nc->stream; 
	nc->stream->devq->ptr = (Stream *)c->stream; 
1990/0227    
	c->stream->devq->other->next = nc->stream->devq; 
	nc->stream->devq->other->next = c->stream->devq; 
1990/0629    
 
	/* 
	 *  up the inuse count of each stream to reflect the 
	 *  pointer from the other stream. 
	 */ 
	if(streamenter(c->stream)<0) 
		panic("pipeattach"); 
	if(streamenter(nc->stream)<0) 
		panic("pipeattach"); 
1990/0227    
	return nc; 
} 
 
1990/0617/sys/src/9/port/devpipe.c:110,1161990/0629/sys/src/9/port/devpipe.c:123,139
1990/0227    
void 
pipeclose(Chan *c) 
{ 
	streamclose(c); 
1990/0629    
	Stream *other; 
 
	other = (Stream *)c->stream->devq->ptr; 
 
	if(waserror()){ 
		streamexit(other, 0); 
		nexterror(); 
	} 
	streamclose(c);		/* close this stream */ 
	streamexit(other, 0);	/* release stream for other half of pipe */ 
	poperror(); 
1990/0227    
} 
 
long 
1990/0617/sys/src/9/port/devpipe.c:164,1771990/0629/sys/src/9/port/devpipe.c:187,193
1990/0227    
static void 
pipeoput(Queue *q, Block *bp) 
{ 
	lock(q); 
	if(q->next) 
		pipeiput(q->next, bp); 
1990/0403    
	else{ 
		print("pipeoput losing block\n"); 
		freeb(bp); 
	} 
1990/0227    
	unlock(q); 
1990/0629    
	PUTNEXT(q, bp); 
1990/0227    
} 
 
/* 
1990/0617/sys/src/9/port/devpipe.c:193,2211990/0629/sys/src/9/port/devpipe.c:209,215
1990/0227    
	 *  send a hangup 
	 */ 
	q = q->other; 
	lock(q); 
	if(q->next){ 
		bp = allocb(0); 
		bp->type = M_HANGUP; 
		pipeiput(q->next, bp); 
	} 
	unlock(q); 
                 
	/* 
	 *  disconnect (possible livelock?) 
	 */ 
	for(;;){ 
		lock(q); 
		if(q->next){ 
			if(!canlock(q->next->other)){ 
				unlock(q); 
				continue; 
			} 
			q->next->other->next = 0; 
			unlock(q->next->other); 
			q->next = 0; 
		} 
		unlock(q); 
		break; 
	} 
1990/0629    
	bp = allocb(0); 
	bp->type = M_HANGUP; 
	PUTNEXT(q, bp); 
1990/0227    
} 


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