From 9234d92d4e274791eff42cc4ea5766ed7a281b17 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 18 Oct 2001 06:06:13 +0000 Subject: [PATCH] 1058. [func] Limited lifetime ticker timers are now available, isc_timertype_limited. --- CHANGES | 3 +++ lib/isc/include/isc/timer.h | 8 ++++++-- lib/isc/timer.c | 23 +++++++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 56e6b9e567..9d353b0a9a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1058. [func] Limited lifetime ticker timers are now available, + isc_timertype_limited. + 1057. [bug] Reloading the server after adding a "file" clause to a zone statement could cause the server to crash due to a typo in change 1016. diff --git a/lib/isc/include/isc/timer.h b/lib/isc/include/isc/timer.h index 6b210725eb..111d4c6327 100644 --- a/lib/isc/include/isc/timer.h +++ b/lib/isc/include/isc/timer.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: timer.h,v 1.28 2001/01/09 21:57:41 bwelling Exp $ */ +/* $Id: timer.h,v 1.29 2001/10/18 06:06:13 marka Exp $ */ #ifndef ISC_TIMER_H #define ISC_TIMER_H 1 @@ -38,6 +38,9 @@ * They are used to implement both (possibly expiring) idle timers and * 'one-shot' timers. * + * 'limited' timers generate a periodic tick event until they reach + * their lifetime when they generate a life timeout event. + * * 'inactive' timers generate no events. * * Timers can change type. It is typical to create a timer as @@ -87,7 +90,8 @@ ISC_LANG_BEGINDECLS typedef enum { isc_timertype_ticker = 0, isc_timertype_once = 1, - isc_timertype_inactive = 2 + isc_timertype_limited = 2, + isc_timertype_inactive = 3 } isc_timertype_t; typedef struct isc_timerevent { diff --git a/lib/isc/timer.c b/lib/isc/timer.c index 574ce0058d..fc85e0ebd8 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: timer.c,v 1.64 2001/06/04 19:33:29 tale Exp $ */ +/* $Id: timer.c,v 1.65 2001/10/18 06:06:12 marka Exp $ */ #include @@ -121,10 +121,13 @@ schedule(isc_timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) { /* * Compute the new due time. */ - if (timer->type == isc_timertype_ticker) { + if (timer->type != isc_timertype_once) { result = isc_time_add(now, &timer->interval, &due); if (result != ISC_R_SUCCESS) return (result); + if (timer->type == isc_timertype_limited && + isc_time_compare(&timer->expires, &due) < 0) + due = timer->expires; } else { if (isc_time_isepoch(&timer->idle)) due = timer->expires; @@ -274,6 +277,8 @@ isc_timer_create(isc_timermgr_t *manager, isc_timertype_t type, REQUIRE(type == isc_timertype_inactive || !(isc_time_isepoch(expires) && isc_interval_iszero(interval))); REQUIRE(timerp != NULL && *timerp == NULL); + REQUIRE(type != isc_timertype_limited || + !(isc_time_isepoch(expires) || isc_interval_iszero(interval))); /* * Get current time. @@ -397,6 +402,8 @@ isc_timer_reset(isc_timer_t *timer, isc_timertype_t type, interval = isc_interval_zero; REQUIRE(type == isc_timertype_inactive || !(isc_time_isepoch(expires) && isc_interval_iszero(interval))); + REQUIRE(type != isc_timertype_limited || + !(isc_time_isepoch(expires) || isc_interval_iszero(interval))); /* * Get current time. @@ -557,6 +564,18 @@ dispatch(isc_timermgr_t *manager, isc_time_t *now) { type = ISC_TIMEREVENT_TICK; post_event = ISC_TRUE; need_schedule = ISC_TRUE; + } else if (timer->type == isc_timertype_limited) { + int cmp; + cmp = isc_time_compare(now, &timer->expires); + if (cmp >= 0) { + type = ISC_TIMEREVENT_LIFE; + post_event = ISC_TRUE; + need_schedule = ISC_FALSE; + } else { + type = ISC_TIMEREVENT_TICK; + post_event = ISC_TRUE; + need_schedule = ISC_TRUE; + } } else if (!isc_time_isepoch(&timer->expires) && isc_time_compare(now, &timer->expires) >= 0) {