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

1992/0619/port/pgrp.c (diff list | history)

1992/0607/sys/src/9/port/pgrp.c:5,791992/0619/sys/src/9/port/pgrp.c:5,14 (short | long | prev | next)
1990/0227    
#include	"fns.h" 
1992/0111    
#include	"../port/error.h" 
1990/0227    
 
1992/0128    
Pgrps pgrpalloc; 
1992/0619    
static Ref pgrpid; 
static Ref mountid; 
1990/0227    
 
1991/0705    
struct 
{ 
	Lock; 
	Egrp	*free; 
}egrpalloc; 
                 
struct 
{ 
	Lock; 
	Fgrp	*free; 
}fgrpalloc; 
                 
1990/0227    
struct{ 
	Lock; 
	Mount	*free; 
1991/1011    
	Mhead	*mhfree; 
1990/0227    
	ulong	mountid; 
}mountalloc; 
                 
void 
1991/0705    
grpinit(void) 
1990/0227    
{ 
	int i; 
	Pgrp *p; 
1991/0705    
	Egrp *e, *ee; 
	Fgrp *f, *fe; 
	Mount *m, *em; 
1991/1011    
	Mhead *hm, *hem; 
1991/1127    
	Crypt *cr; 
1990/0227    
                 
1992/0128    
	i = conf.npgrp*sizeof(Crypt); 
	cr = ialloc(i, 0); 
	pgrpalloc.cryptbase = (ulong)cr; 
	pgrpalloc.crypttop = (ulong)cr + i; 
1990/1110    
	pgrpalloc.arena = ialloc(conf.npgrp*sizeof(Pgrp), 0); 
	pgrpalloc.free = pgrpalloc.arena; 
1990/0227    
                 
	p = pgrpalloc.free; 
1991/1011    
	for(i=0; i<conf.npgrp; i++,p++) { 
1990/1110    
		p->index = i; 
1990/0227    
		p->next = p+1; 
1991/1127    
		p->crypt = cr++; 
1990/0227    
	} 
1990/0825    
	p[-1].next = 0; 
1990/0227    
                 
1991/0705    
	egrpalloc.free = ialloc(conf.npgrp*sizeof(Egrp), 0); 
	ee = &egrpalloc.free[conf.npgrp]; 
	for(e = egrpalloc.free; e < ee; e++) { 
		e->next = e+1; 
1991/1018    
		e->etab = ialloc(conf.npgenv*sizeof(Env), 0); 
1991/0705    
	} 
	e[-1].next = 0; 
1990/0227    
                 
1991/0705    
	fgrpalloc.free = ialloc(conf.nproc*sizeof(Fgrp), 0); 
	fe = &fgrpalloc.free[conf.nproc-1]; 
	for(f = fgrpalloc.free; f < fe; f++) 
		f->next = f+1; 
	f->next = 0; 
1990/0227    
} 
                 
Pgrp* 
1990/1110    
pgrptab(int i) 
{ 
	return &pgrpalloc.arena[i]; 
} 
                 
void 
1992/0428    
pgrpnote(ulong noteid, char *a, long n, int flag) 
1990/1110    
{ 
1992/0428    
	Proc *p, *ep; 
1992/0607/sys/src/9/port/pgrp.c:109,1301992/0619/sys/src/9/port/pgrp.c:44,55
1990/0227    
{ 
	Pgrp *p; 
 
1991/0705    
	for(;;) { 
		lock(&pgrpalloc); 
		if(p = pgrpalloc.free){ 
			pgrpalloc.free = p->next; 
			p->ref = 1; 
			p->pgrpid = ++pgrpalloc.pgrpid; 
1991/1127    
			memset(p->crypt, 0, sizeof *p->crypt); 
1991/0806    
			memset(p->rendhash, 0, sizeof(p->rendhash)); 
1991/1011    
			memset(p->mnthash, 0, sizeof(p->mnthash)); 
1991/0705    
			unlock(&pgrpalloc); 
			return p; 
		} 
1990/0227    
		unlock(&pgrpalloc); 
1991/0705    
		resrcwait("no pgrps"); 
1990/0227    
	} 
1992/0520    
	return 0;		/* not reached */ 
1992/0619    
	p = smalloc(sizeof(Pgrp)+sizeof(Crypt)); 
	p->ref = 1; 
	/* This needs to have its own arena for protection */ 
	p->crypt = (Crypt*)((uchar*)p+sizeof(Pgrp)); 
	p->pgrpid = incref(&pgrpid); 
	return p; 
1991/0705    
} 
 
Egrp* 
1992/0607/sys/src/9/port/pgrp.c:132,1501992/0619/sys/src/9/port/pgrp.c:57,68
1991/0705    
{ 
	Egrp *e; 
 
	for(;;) { 
		lock(&egrpalloc); 
		if(e = egrpalloc.free) { 
			egrpalloc.free = e->next; 
			e->ref = 1; 
			e->nenv = 0; 
			unlock(&egrpalloc); 
			return e; 
		} 
		unlock(&egrpalloc); 
		resrcwait("no envgrps"); 
	} 
1992/0520    
	return 0;		/* not reached */ 
1992/0619    
	e = smalloc(sizeof(Egrp)+sizeof(Env)*conf.npgenv); 
 
	/* This is a sleazy hack to make malloc work .. devenv need rewriting. */ 
	e->etab = (Env*)((uchar*)e+sizeof(Egrp)); 
	e->ref = 1; 
	return e; 
1991/0705    
} 
 
Fgrp* 
1992/0607/sys/src/9/port/pgrp.c:152,1711992/0619/sys/src/9/port/pgrp.c:70,78
1991/0705    
{ 
	Fgrp *f; 
 
	for(;;) { 
		lock(&fgrpalloc); 
		if(f = fgrpalloc.free) { 
			fgrpalloc.free = f->next; 
			f->ref = 1; 
			f->maxfd = 0; 
			memset(f->fd, 0, sizeof(f->fd)); 
			unlock(&fgrpalloc); 
			return f; 
		} 
		unlock(&fgrpalloc); 
		resrcwait("no filegrps"); 
	} 
1992/0520    
	return 0;		/* not reached */ 
1992/0619    
	f = smalloc(sizeof(Fgrp)); 
	f->ref = 1; 
	return f; 
1991/0705    
} 
 
Fgrp* 
1992/0607/sys/src/9/port/pgrp.c:221,2351992/0619/sys/src/9/port/pgrp.c:128,138
1991/1011    
				close(f->from); 
				mountfree(f->mount); 
				next = f->hash; 
				mntheadfree(f); 
1992/0619    
				free(f); 
1990/0227    
			} 
1991/1011    
		} 
                 
1990/0227    
		lock(&pgrpalloc); 
		p->next = pgrpalloc.free; 
		pgrpalloc.free = p; 
1991/0212    
		qunlock(&p->debug); 
1990/0227    
		unlock(&pgrpalloc); 
1992/0619    
		free(p); 
1990/0227    
	} 
} 
 
1992/0607/sys/src/9/port/pgrp.c:243,2521992/0619/sys/src/9/port/pgrp.c:146,153
1991/1018    
		e = eg->etab; 
		for(i=0; i<eg->nenv; i++, e++) 
			envpgclose(e); 
1991/0705    
		lock(&egrpalloc); 
1991/1018    
		eg->next = egrpalloc.free; 
		egrpalloc.free = eg; 
1991/0705    
		unlock(&egrpalloc); 
1992/0619    
 
		free(eg); 
1991/0705    
	} 
} 
 
1992/0607/sys/src/9/port/pgrp.c:261,2701992/0619/sys/src/9/port/pgrp.c:162,168
1991/0705    
			if(c = f->fd[i]) 
				close(c); 
 
		lock(&fgrpalloc); 
		f->next = fgrpalloc.free; 
		fgrpalloc.free = f; 
		unlock(&fgrpalloc); 
1992/0619    
		free(f); 
1991/0705    
	} 
} 
 
1992/0607/sys/src/9/port/pgrp.c:274,3041992/0619/sys/src/9/port/pgrp.c:172,183
1990/0227    
{ 
1991/1011    
	Mount *m, *f, *e; 
1990/0227    
 
1991/1011    
	for(;;) { 
		lock(&mountalloc); 
		if(m = mountalloc.free){		/* assign = */ 
			mountalloc.free = m->next; 
			m->mountid = ++mountalloc.mountid; 
			unlock(&mountalloc); 
			m->next = 0; 
			m->head = mh; 
			m->to = to; 
			incref(to); 
			return m; 
		} 
1990/0227    
		unlock(&mountalloc); 
                 
1991/1011    
		m = (Mount*)VA(kmap(newpage(0, 0, 0))); 
		e = &m[(BY2PG/sizeof(Mount))-1]; 
		for(f = m; f < e; f++) 
			f->next = f+1; 
                 
1990/0227    
		lock(&mountalloc); 
1991/1011    
		e->next = mountalloc.free; 
1990/0227    
		mountalloc.free = m; 
		unlock(&mountalloc); 
	} 
1992/0520    
	return 0;	/* not reached */ 
1992/0619    
	m = smalloc(sizeof(Mount)); 
	m->to = to; 
	m->head = mh; 
	incref(to); 
	m->mountid = incref(&mountid); 
	return m; 
1990/0227    
} 
 
void 
1992/0607/sys/src/9/port/pgrp.c:331,3371992/0619/sys/src/9/port/pgrp.c:210,216
1991/1011    
	for(h = from->mnthash; h < e; h++) { 
1991/1113    
		l = tom++; 
1991/1011    
		for(f = *h; f; f = f->hash) { 
			mh = newmnthead(); 
1992/0619    
			mh = smalloc(sizeof(Mhead)); 
1991/1011    
			mh->from = f->from; 
			incref(mh->from); 
			*l = mh; 
1992/0607/sys/src/9/port/pgrp.c:347,3911992/0619/sys/src/9/port/pgrp.c:226,232
1991/1011    
	runlock(&from->ns); 
} 
1991/0514    
 
1991/1011    
Mhead * 
newmnthead(void) 
{ 
	Mhead *mh, *f, *e; 
                 
	for(;;) { 
		lock(&mountalloc); 
		if(mh = mountalloc.mhfree) {		/* Assign '=' */ 
			mountalloc.mhfree = mh->hash; 
			unlock(&mountalloc); 
			mh->hash = 0; 
			mh->mount = 0; 
			return mh; 
		} 
		unlock(&mountalloc); 
                 
		mh = (Mhead*)VA(kmap(newpage(0, 0, 0))); 
		e = &mh[(BY2PG/sizeof(Mhead))-1]; 
		for(f = mh; f < e; f++) 
			f->hash = f+1; 
                 
		lock(&mountalloc); 
		e->hash = mountalloc.mhfree; 
		mountalloc.mhfree = mh; 
		unlock(&mountalloc); 
	} 
1992/0520    
	return 0;		/* not reached */ 
1991/1011    
} 
                 
void 
mntheadfree(Mhead *mh) 
{ 
	lock(&mountalloc); 
	mh->hash = mountalloc.mhfree; 
	mountalloc.mhfree = mh; 
	unlock(&mountalloc); 
} 
                 
void 
mountfree(Mount *m) 
{ 
	Mount *f; 
1992/0607/sys/src/9/port/pgrp.c:392,4001992/0619/sys/src/9/port/pgrp.c:233,240
1991/1011    
 
	for(f = m; f->next; f = f->next) 
		close(f->to); 
1992/0619    
 
1991/1011    
	close(f->to); 
	lock(&mountalloc); 
	f->next = mountalloc.free; 
	mountalloc.free = m; 
	unlock(&mountalloc); 
1992/0619    
 
	free(f); 
1990/0227    
} 


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