FreeBSD/contrib/bsnmp/snmpd/main.c
/*
 * Start a one-shot timer
 */
Start a one-shot timer
Start a one - shot timer
void *
timer_start(u_int ticks, void (*func)(void *), void *udata, struct lmodule *mod)
{
	struct timer *tp;
#ifndef USE_LIBBEGEMOT
	struct timespec due;
#endif
	if ((tp = malloc(sizeof(struct timer))) == NULL) {
		syslog(LOG_CRIT, "out of memory for timer");
		exit(1);
	}
#ifndef USE_LIBBEGEMOT
	due = evAddTime(evNowTime(),
	    evConsTime(ticks / 100, (ticks % 100) * 10000));
#endif
	tp->udata = udata;
	tp->owner = mod;
	tp->func = func;
	LIST_INSERT_HEAD(&timer_list, tp, link);
#ifdef USE_LIBBEGEMOT
	if ((tp->id = poll_start_timer(ticks * 10, 0, tfunc, tp)) < 0) {
		syslog(LOG_ERR, "cannot set timer: %m");
		exit(1);
	}
#else
	if (evSetTimer(evctx, tfunc, tp, due, evConsTime(0, 0), &tp->id)
	    == -1) {
		syslog(LOG_ERR, "cannot set timer: %m");
		exit(1);
	}
#endif
	return (tp);
}
void * timer_start ( u_int ticks , void ( * func ) ( void * ) , void * udata , struct lmodule * mod ) { struct timer * tp ; #ifndef USE_LIBBEGEMOT struct timespec due ; #endif if ( ( tp = malloc ( sizeof ( struct timer ) ) ) == NULL ) { syslog ( LOG_CRIT , " " ) ; exit ( 1 ) ; } #ifndef USE_LIBBEGEMOT due = evAddTime ( evNowTime ( ) , evConsTime ( ticks / 100 , ( ticks % 100 ) * 10000 ) ) ; #endif tp -> udata = udata ; tp -> owner = mod ; tp -> func = func ; LIST_INSERT_HEAD ( & timer_list , tp , link ) ; #ifdef USE_LIBBEGEMOT if ( ( tp -> id = poll_start_timer ( ticks * 10 , 0 , tfunc , tp ) ) < 0 ) { syslog ( LOG_ERR , " " ) ; exit ( 1 ) ; } #else if ( evSetTimer ( evctx , tfunc , tp , due , evConsTime ( 0 , 0 ) , & tp -> id ) == -1 ) { syslog ( LOG_ERR , " " ) ; exit ( 1 ) ; } #endif return ( tp ) ; }
Start a one-shot timer
Start a one - shot timer