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

2002/0405/pc/cycintr.c (diff list | history)

pc/cycintr.c on 2000/0623
2000/0623    
#include "u.h" 
#include "../port/lib.h" 
#include "mem.h" 
#include "dat.h" 
#include "fns.h" 
#include "io.h" 
 
 
static struct 
{ 
	Lock; 
2002/0405    
	Timer	*ci; 
}timers; 
2000/0623    
 
2000/0627    
/* 
 * called by clockintrsched() 
 */ 
vlong 
2002/0405    
timernext(void) 
2000/0623    
{ 
2002/0405    
	Timer *ci; 
2000/0627    
	vlong when; 
 
2002/0405    
	ilock(&timers); 
2000/0627    
	when = 0; 
2002/0405    
	ci = timers.ci; 
2000/0627    
	if(ci != nil) 
		when = ci->when; 
2002/0405    
	iunlock(&timers); 
2000/0627    
	return when; 
2000/0623    
} 
 
2000/0627    
vlong 
2002/0405    
checktimer(Ureg *u, void*) 
2000/0623    
{ 
2002/0405    
	Timer *ci; 
2000/0627    
	vlong when; 
2000/0623    
 
2002/0405    
	ilock(&timers); 
	while(ci = timers.ci){ 
2000/0627    
		when = ci->when; 
		if(when > fastticks(nil)){ 
2002/0405    
			iunlock(&timers); 
2000/0627    
			return when; 
		} 
2002/0405    
		timers.ci = ci->next; 
		iunlock(&timers); 
2000/0623    
		(*ci->f)(u, ci); 
2002/0405    
		ilock(&timers); 
2000/0623    
	} 
2002/0405    
	iunlock(&timers); 
2000/0627    
	return 0; 
2000/0623    
} 
 
void 
2002/0405    
timeradd(Timer *nci) 
2000/0623    
{ 
2002/0405    
	Timer *ci, **last; 
2000/0623    
 
2002/0405    
	ilock(&timers); 
	last = &timers.ci; 
2000/0623    
	while(ci = *last){ 
		if(ci == nci){ 
			*last = ci->next; 
			break; 
		} 
		last = &ci->next; 
	} 
 
2002/0405    
	last = &timers.ci; 
2000/0623    
	while(ci = *last){ 
		if(ci->when > nci->when) 
			break; 
		last = &ci->next; 
	} 
	nci->next = *last; 
	*last = nci; 
2002/0405    
	iunlock(&timers); 
2000/0623    
} 
 
void 
2002/0405    
timerdel(Timer *dci) 
2000/0623    
{ 
2002/0405    
	Timer *ci, **last; 
2000/0623    
 
2002/0405    
	ilock(&timers); 
	last = &timers.ci; 
2000/0623    
	while(ci = *last){ 
		if(ci == dci){ 
			*last = ci->next; 
			break; 
		} 
		last = &ci->next; 
	} 
2002/0405    
	iunlock(&timers); 
2000/0623    
} 


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