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

1992/0903/port/tcptimer.c (diff list | history)

1992/0807/sys/src/9/port/tcptimer.c:7,191992/0903/sys/src/9/port/tcptimer.c:7,60 (short | long | prev | next)
1991/0424    
#include 	"arp.h" 
#include 	"ipdat.h" 
 
/* Head of running timer chain */ 
Timer 	*timers; 
QLock 	timerlock; 
Rendez	Tcpack; 
1992/0903    
static	Timer 	*timers;	/* List of active timers */ 
static	QLock 	tl;		/* Protect timer list */ 
static	Rendez	Tcpack; 
1991/0424    
Rendez	tcpflowr; 
 
1992/0903    
static void 
deltimer(Timer *t) 
{ 
	if(timers == t) 
		timers = t->next; 
 
	if(t->next) 
		t->next->prev = t->prev; 
 
	if(t->prev) 
		t->prev->next = t->next; 
} 
 
/* 
 * Poke each tcp connection to recompute window size and 
 * acknowledgement timer 
 */ 
 
1991/0424    
void 
1992/0903    
tcpflow(void *x) 
{ 
	Ipifc *ifc; 
	Ipconv *cp, **p, **etab; 
 
	ifc = x; 
	etab = &ifc->conv[Nipconv]; 
 
	for(;;) { 
		sleep(&tcpflowr, return0, 0); 
 
		for(p = ifc->conv; p < etab; p++) { 
			cp = *p; 
			if(cp == 0) 
				break; 
			if(cp->readq && cp->ref != 0 && !QFULL(cp->readq->next)) { 
				tcprcvwin(cp); 
				tcpacktimer(cp); 
			} 
		} 
	} 
} 
 
void 
1991/0424    
tcpackproc(void *junk) 
{ 
	Timer *t,*tp; 
1992/0807/sys/src/9/port/tcptimer.c:23,521992/0903/sys/src/9/port/tcptimer.c:64,81
1991/0424    
	for(;;) { 
		expired = 0; 
 
		qlock(&timerlock); 
1992/0903    
		qlock(&tl); 
1991/0424    
		for(t = timers;t != 0; t = tp) { 
			tp = t->next; 
			if(tp == t) 
				panic("Timer loop at %lux\n",(long)tp); 
	                 
1992/0314    
 			if(t->state == TIMER_RUN) 
			if(--(t->count) == 0){ 
1991/0424    
                 
				/* Delete from active timer list */ 
				if(timers == t) 
					timers = t->next; 
				if(t->next != 0) 
					t->next->prev = t->prev; 
				if(t->prev != 0) 
					t->prev->next = t->next; 
                 
1992/0903    
				deltimer(t); 
1991/0424    
				t->state = TIMER_EXPIRE; 
				/* Put on head of expired timer list */ 
				t->next = expired; 
				expired = t; 
			} 
		} 
		qunlock(&timerlock); 
1992/0903    
		qunlock(&tl); 
1991/0424    
 
1992/0314    
		for(;;) { 
			t = expired; 
1992/0807/sys/src/9/port/tcptimer.c:58,1331992/0903/sys/src/9/port/tcptimer.c:87,124
1992/0314    
			if(t->func) 
1991/0424    
				(*t->func)(t->arg); 
		} 
                 
		tsleep(&Tcpack, return0, 0, MSPTICK); 
	} 
} 
 
void 
start_timer(Timer *t) 
1992/0903    
tcpgo(Timer *t) 
1991/0424    
{ 
                 
	if(t == 0 || t->start == 0) 
		return; 
 
	qlock(&timerlock); 
                 
1992/0903    
	qlock(&tl); 
1991/0424    
	t->count = t->start; 
	if(t->state != TIMER_RUN){ 
1992/0903    
	if(t->state != TIMER_RUN) { 
1991/0424    
		t->state = TIMER_RUN; 
		/* Put on head of active timer list */ 
		t->prev = 0; 
		t->next = timers; 
		if(t->next != 0) 
1992/0903    
		if(t->next) 
1991/0424    
			t->next->prev = t; 
		timers = t; 
	} 
	qunlock(&timerlock); 
1992/0903    
	qunlock(&tl); 
1991/0424    
} 
 
void 
stop_timer(Timer *t) 
1992/0903    
tcphalt(Timer *t) 
1991/0424    
{ 
	if(t == 0) 
		return; 
 
	qlock(&timerlock); 
                 
	if(t->state == TIMER_RUN){ 
		/* Delete from active timer list */ 
		if(timers == t) 
			timers = t->next; 
		if(t->next != 0) 
			t->next->prev = t->prev; 
		if(t->prev != 0) 
			t->prev->next = t->next; 
	} 
1992/0903    
	qlock(&tl); 
	if(t->state == TIMER_RUN) 
		deltimer(t); 
1991/0424    
	t->state = TIMER_STOP; 
                 
	qunlock(&timerlock); 
1992/0903    
	qunlock(&tl); 
1991/0424    
} 
                 
void 
1992/0626    
tcpflow(void *x) 
1991/0424    
{ 
1992/0626    
	Ipifc *ifc; 
	Ipconv *cp, **p, **etab; 
1991/0424    
                 
1992/0626    
	ifc = x; 
	etab = &ifc->conv[Nipconv]; 
1992/0807    
                 
1991/0424    
	for(;;) { 
		sleep(&tcpflowr, return0, 0); 
                 
1992/0626    
		for(p = ifc->conv; p < etab; p++) { 
			cp = *p; 
			if(cp == 0) 
				break; 
1992/0807    
			if(cp->readq && cp->ref != 0 && !QFULL(cp->readq->next)) { 
1992/0626    
				tcprcvwin(cp); 
				tcp_acktimer(cp); 
1991/0424    
			} 
		} 
	} 
} 
                 


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