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

1992/0620/port/chan.c (diff list | history)

1992/0619/sys/src/9/port/chan.c:5,131992/0620/sys/src/9/port/chan.c:5,15 (short | long | prev | next)
1990/0227    
#include	"fns.h" 
1992/0111    
#include	"../port/error.h" 
1990/0227    
 
struct{ 
1992/0620    
struct 
{ 
1990/0227    
	Lock; 
	Chan	*free; 
1992/0620    
	int	fid; 
1990/0227    
}chanalloc; 
 
int 
1992/0619/sys/src/9/port/chan.c:38,591992/0620/sys/src/9/port/chan.c:40,45
1990/0227    
} 
 
void 
chaninit(void) 
{ 
	int i; 
	Chan *c; 
                 
	chanalloc.free = ialloc(conf.nchan*sizeof(Chan), 0); 
                 
	c = chanalloc.free; 
	for(i=0; i<conf.nchan-1; i++,c++){ 
		c->fid = i; 
		c->next = c+1; 
	} 
	c->next = 0; 
} 
                 
void 
chandevreset(void) 
{ 
	int i; 
1992/0619/sys/src/9/port/chan.c:75,1041992/0620/sys/src/9/port/chan.c:61,96
1990/0227    
newchan(void) 
{ 
	Chan *c; 
1992/0620    
	int nfid; 
1990/0227    
 
1991/1011    
	for(;;) { 
		lock(&chanalloc); 
		if(c = chanalloc.free) { 
			chanalloc.free = c->next; 
1991/1206    
			/* if you get an error before associating with a dev, 
			   close calls rootclose, a nop */ 
1991/1011    
			c->type = 0; 
			c->flag = 0; 
			c->ref = 1; 
			unlock(&chanalloc); 
			c->dev = 0; 
			c->offset = 0; 
			c->mnt = 0; 
			c->stream = 0; 
			c->aux = 0; 
			c->mchan = 0; 
			c->mqid = (Qid){0, 0}; 
			return c; 
		} 
1990/0227    
		unlock(&chanalloc); 
1991/1011    
		resrcwait("no chans\n"); 
1992/0620    
	SET(nfid); 
 
	lock(&chanalloc); 
	c = chanalloc.free; 
	if(c) 
		chanalloc.free = c->next; 
	else 
		nfid = ++chanalloc.fid; 
	unlock(&chanalloc); 
 
	if(c == 0) { 
		c = smalloc(sizeof(Chan)); 
		c->fid = nfid; 
1990/0227    
	} 
1992/0520    
	return 0;	/* not reached */ 
1992/0620    
 
	/* if you get an error before associating with a dev, 
	   close calls rootclose, a nop */ 
	c->type = 0; 
	c->flag = 0; 
	c->ref = 1; 
	c->dev = 0; 
	c->offset = 0; 
	c->mnt = 0; 
	c->stream = 0; 
	c->aux = 0; 
	c->mchan = 0; 
	c->mqid = (Qid){0, 0}; 
	return c; 
1990/0227    
} 
 
void 


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