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

1992/0602/port/proc.c (diff list | history)

1992/0527/sys/src/9/port/proc.c:317,3451992/0602/sys/src/9/port/proc.c:317,348 (short | long | prev | next)
Rewrite tsleep to avoid explicit Alarm structures. Now alarm info is in Proc. New tsleep can call regular sleep, avoiding duplicate implementation.
rsc Mon Mar 20 17:14:25 2006
1990/0227    
} 
 
void 
tsleep(Rendez *r, int (*f)(void*), void *arg, int ms) 
1992/0602    
tsleep(Rendez *r, int (*fn)(void*), void *arg, int ms) 
1990/0227    
{ 
	Alarm *a; 
1991/0727    
	Proc *p; 
1992/0519    
	int s; 
1992/0602    
	ulong when; 
	Proc *p, *f, **l, **i; 
1990/0227    
 
1991/0727    
	p = u->p; 
1990/0227    
	sleep1(r, f, arg); 
1991/0727    
	if(p->notepending == 0){ 
		a = alarm(ms, twakeme, r); 
		sched();	/* notepending may go true while asleep */ 
		cancel(a); 
1992/0602    
	when = MS2TK(ms)+MACHP(0)->ticks; 
	i = &talarm.list; 
 
	lock(&talarm); 
	l = &talarm.list; 
	for(f = talarm.list; f; f = f->tlink) { 
		if(f == p) 
			*l = p->tlink; 
		if(f->twhen && f->twhen < when) 
			i = &f->tlink; 
		l = &f->tlink; 
1991/0727    
	} 
	if(p->notepending){ 
		p->notepending = 0; 
1992/0519    
		s = splhi(); 
1991/0805    
		lock(r); 
		if(r->p == p) 
			r->p = 0; 
		unlock(r); 
1992/0519    
		splx(s); 
1990/11211    
		error(Eintr); 
1990/0227    
	} 
1992/0602    
	p->trend = r; 
	p->twhen = when; 
	p->tlink = *i; 
	*i = p; 
	unlock(&talarm); 
 
	sleep(r, fn, arg); 
	p->twhen = 0; 
1990/0227    
} 
 
void 
1992/0527/sys/src/9/port/proc.c:356,3821992/0602/sys/src/9/port/proc.c:359,368
1991/0705    
		if(p->state != Wakeme)  
			panic("wakeup: state"); 
1990/0227    
		p->r = 0; 
1992/0319    
if((p->sched.pc&KZERO) != KZERO){ 
	spllo(); 
	panic("wakeup"); 
} 
1990/0227    
		ready(p); 
	} 
	unlock(r); 
	splx(s); 
} 
                 
1990/03091    
void 
wakeme(Alarm *a) 
{ 
	ready((Proc*)(a->arg)); 
	cancel(a); 
} 
                 
void 
twakeme(Alarm *a) 
{ 
	wakeup((Rendez*)(a->arg)); 
} 
 
1990/0227    
int 


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