summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/mqueue.c82
-rw-r--r--lib/mqueue.h9
-rw-r--r--lib/qpnexus.c2
-rw-r--r--lib/qpselect.c29
-rw-r--r--lib/qpselect.h2
-rw-r--r--lib/qpthreads.c40
-rw-r--r--lib/qpthreads.h65
-rw-r--r--lib/qtime.c2
-rw-r--r--lib/qtime.h103
-rw-r--r--lib/qtimers.c13
-rw-r--r--lib/qtimers.h60
-rw-r--r--lib/vty.c4
12 files changed, 202 insertions, 209 deletions
diff --git a/lib/mqueue.c b/lib/mqueue.c
index b07dce6b..5fe892c2 100644
--- a/lib/mqueue.c
+++ b/lib/mqueue.c
@@ -44,21 +44,21 @@
*
* For condition variables there is a timeout mechanism so that waiters
* are woken up at least every now and then. The message queue maintains
- * current timeout time and timeout interval variables. Each time a waiter
- * waits it will do:
+ * a timeout time and a timeout interval. The timeout time is a qtime_mono_t
+ * time -- so is monotonic.
*
- * next = now + interval
- * if (now > current) || (next <= current)
- * current = next and return (don't wait)
- * else
- * wait until current
+ * When waiting, an explicit timeout may be given, otherwise the stored timeout
+ * will be used:
*
- * If the wait times out, the current is set to current + interval.
+ * wait until explicit/stored timeout
+ * if times out and there is a stored interval:
+ * new stored timeout = stored timeout + stored interval
+ * if new stored timeout < time now
+ * new stored timeout = time now + stored interval
*
- * The effect of this is to return at least at regular intervals from the wait,
- * provided the queue is waited on within the timeout period. If the queue is
- * waited on after the current timeout time, it returns immediately, updating
- * the current timeout time -- the "clock" slips.
+ * Left to its own devices, this will produce a regular timeout every interval,
+ * assuming that the queue is waited on within the interval. Otherwise the
+ * "clock" will slip.
*
* There is a default timeout period. The period may be set "infinite".
*
@@ -116,8 +116,8 @@ mqueue_init_new(mqueue_queue mq, enum mqueue_queue_type type)
if (MQUEUE_DEFAULT_INTERVAL != 0)
{
mq->kick.cond.interval = MQUEUE_DEFAULT_INTERVAL ;
- mq->kick.cond.timeout =
- qpt_cond_get_timeout_time(MQUEUE_DEFAULT_INTERVAL) ;
+ mq->kick.cond.timeout = qt_get_monotonic()
+ + MQUEUE_DEFAULT_INTERVAL ;
} ;
break;
@@ -146,7 +146,7 @@ mqueue_set_timeout_interval(mqueue_queue mq, qtime_t interval)
(mq->type == mqt_cond_broadcast) ) ;
mq->kick.cond.interval = interval ;
- mq->kick.cond.timeout = (interval > 0) ? qpt_cond_get_timeout_time(interval)
+ mq->kick.cond.timeout = (interval > 0) ? qt_get_monotonic() + interval
: 0 ;
qpt_mutex_unlock(&mq->mutex) ;
} ;
@@ -339,7 +339,13 @@ mqueue_enqueue(mqueue_queue mq, mqueue_block mb, int priority)
* case for:
*
* * mqt_cond_xxxx type message queues, will wait on the condition variable,
- * and may time-out. (mtsig argument MUST be NULL.)
+ * and may timeout.
+ *
+ * If the argument is NULL, uses the already set up timeout, if there is
+ * one.
+ *
+ * If the argument is not NULL, it is a pointer to a qtime_mono_t time,
+ * to be used as the new timeout time.
*
* * mqt_signal_xxxx type message queues, will register the given signal
* (mtsig argument MUST be provided), and return immediately.
@@ -348,11 +354,14 @@ mqueue_enqueue(mqueue_queue mq, mqueue_block mb, int priority)
*/
mqueue_block
-mqueue_dequeue(mqueue_queue mq, int wait, mqueue_thread_signal mtsig)
+mqueue_dequeue(mqueue_queue mq, int wait, void* arg)
{
mqueue_block mb ;
mqueue_thread_signal last ;
+ mqueue_thread_signal mtsig ;
+ qtime_mono_t timeout_time ;
+
qpt_mutex_lock(&mq->mutex) ;
while (1)
@@ -370,37 +379,36 @@ mqueue_dequeue(mqueue_queue mq, int wait, mqueue_thread_signal mtsig)
{
case mqt_cond_unicast: /* Now wait here */
case mqt_cond_broadcast:
- dassert(mtsig == NULL) ;
-
- if (mq->kick.cond.interval <= 0)
+ if ((arg == NULL) && (mq->kick.cond.interval <= 0))
qpt_cond_wait(&mq->kick.cond.wait_here, &mq->mutex) ;
else
{
- qtime_t now = qpt_cond_get_timeout_time(0) ;
-
-#if QPT_COND_CLOCK_MONOTONIC
- dassert(now >= (mq->kick.cond.timeout - mq->kick.cond.interval)) ;
- if (now > mq->kick.cond.timeout)
-#else
- if ( (now > mq->kick.cond.timeout)
- || (now < (mq->kick.cond.timeout - mq->kick.cond.interval)) )
-#endif
+ timeout_time = (arg != NULL) ? *(qtime_mono_t*)arg
+ : mq->kick.cond.timeout ;
+
+ if (qpt_cond_timedwait(&mq->kick.cond.wait_here, &mq->mutex,
+ timeout_time) == 0)
{
- /* the "clock" has slipped. Reset it and return now. */
- mq->kick.cond.timeout = now + mq->kick.cond.interval ;
+ /* Timed out -- update timeout time, if required */
+ if (mq->kick.cond.interval > 0)
+ {
+ qtime_mono_t now = qt_get_monotonic() ;
+ timeout_time = mq->kick.cond.timeout
+ + mq->kick.cond.interval ;
+ if (timeout_time < now)
+ timeout_time = now + mq->kick.cond.interval ;
+
+ mq->kick.cond.timeout = timeout_time ;
+ } ;
+
goto done ; /* immediate return. mb == NULL */
- }
- else
- {
- if (qpt_cond_timedwait(&mq->kick.cond.wait_here, &mq->mutex,
- mq->kick.cond.timeout) == 0)
- mq->kick.cond.timeout += mq->kick.cond.interval ;
} ;
} ;
break ;
case mqt_signal_unicast: /* Register desire for signal */
case mqt_signal_broadcast:
+ mtsig = arg ;
dassert(mtsig != NULL) ;
last = mq->kick.signal.tail ;
diff --git a/lib/mqueue.h b/lib/mqueue.h
index aff3e154..5c10911b 100644
--- a/lib/mqueue.h
+++ b/lib/mqueue.h
@@ -23,6 +23,7 @@
#define _ZEBRA_MQUEUE_H
#include "qpthreads.h"
+#include "qtime.h"
/*==============================================================================
*/
@@ -76,9 +77,9 @@ enum mqueue_queue_type {
#endif
struct mqueue_queue_cond {
- qpt_cond_t wait_here ;
- qtime_t timeout ;
- qtime_t interval ;
+ qpt_cond_t wait_here ;
+ qtime_mono_t timeout ;
+ qtime_t interval ;
} ;
struct mqueue_queue_signal {
@@ -132,7 +133,7 @@ void
mqueue_enqueue(mqueue_queue mq, mqueue_block mb, int priority) ;
mqueue_block
-mqueue_dequeue(mqueue_queue mq, int wait, mqueue_thread_signal mtsig) ;
+mqueue_dequeue(mqueue_queue mq, int wait, void* arg) ;
int
mqueue_done_waiting(mqueue_queue mq, mqueue_thread_signal mtsig) ;
diff --git a/lib/qpnexus.c b/lib/qpnexus.c
index fc4d6b9d..01985d29 100644
--- a/lib/qpnexus.c
+++ b/lib/qpnexus.c
@@ -90,7 +90,7 @@ qpn_start(void* arg)
while (!qpn->terminate)
{
- qtime_t now = qtimer_time_now();
+ qtime_mono_t now = qt_get_monotonic();
/* process timers */
while (qtimer_pile_dispatch_next(qpn->pile, now))
diff --git a/lib/qpselect.c b/lib/qpselect.c
index 9f5417d0..44ab5e56 100644
--- a/lib/qpselect.c
+++ b/lib/qpselect.c
@@ -53,7 +53,10 @@
* may then be enabled/disabled for any combination of error/read/write
* "mode" events.
*
- * * a timeout
+ * * a timeout *time*
+ *
+ * This is a qtime monotonic time at which to time out. (This is unlike
+ * pselect() itself, which takes a timeout interval.)
*
* Infinite timeouts are not supported.
*
@@ -275,7 +278,7 @@ qps_set_signal(qps_selection qps, int signum, sigset_t sigmask)
*
* There is no support for an infinite timeout.
*
- * Returns: -1 => EINTR occurred
+ * Returns: -1 => EINTR occurred -- ie a signal has gone off
* 0 => hit timeout -- no files are ready
* > 0 => there are this many files ready in one or more modes
*
@@ -284,7 +287,7 @@ qps_set_signal(qps_selection qps, int signum, sigset_t sigmask)
* The qps_dispatch_next() processes the returns from pselect().
*/
int
-qps_pselect(qps_selection qps, qtime_t timeout)
+qps_pselect(qps_selection qps, qtime_mono_t timeout)
{
struct timespec ts ;
qps_mnum_t mnum ;
@@ -301,7 +304,7 @@ qps_pselect(qps_selection qps, qtime_t timeout)
/* given count of fds -- but it does no harm to be tidy, and should */
/* not have to do this often.) */
if (qps->pend_count != 0)
- qps_super_set_zero(qps->enabled, qps_mnum_count) ;
+ qps_super_set_zero(qps->enabled, qps_mnum_count) ;
/* Prepare the argument/result bitmaps */
/* Capture pend_mnum and tried_count[] */
@@ -336,13 +339,21 @@ qps_pselect(qps_selection qps, qtime_t timeout)
qtime2timespec(&ts, timeout),
(qps->signum != 0) ? &qps->sigmask : NULL) ;
- qps->pend_count = (n >= 0) ? n : 0 ; /* avoid setting -ve pend_count */
+ /* If have something, set and return the pending count. */
+ if (n > 0)
+ {
+ assert(qps->pend_mnum < qps_mnum_count) ; /* expected something */
+
+ return qps->pend_count = n ; /* set and return pending count */
+ } ;
+
+ /* Flush the results vectors -- not apparently done if n <= 0) */
+ qps_super_set_zero(qps->enabled, qps_mnum_count) ;
- /* if 1 or more pending results, then must have at least one pending mode */
- assert((n <= 0) || (qps->pend_mnum < qps_mnum_count)) ;
+ qps->pend_count = 0 ; /* nothing pending */
- /* Return appropriately, if we can */
- if ((n >= 0) || (errno == EINTR))
+ /* Return appropriately, if we can */
+ if ((n == 0) || (errno == EINTR))
return n ;
zabort_errno("Failed in pselect") ;
diff --git a/lib/qpselect.h b/lib/qpselect.h
index 6aeca52c..1e67d174 100644
--- a/lib/qpselect.h
+++ b/lib/qpselect.h
@@ -181,7 +181,7 @@ void
qps_set_signal(qps_selection qps, int signum, sigset_t sigmask) ;
int
-qps_pselect(qps_selection qps, qtime_t timeout) ;
+qps_pselect(qps_selection qps, qtime_mono_t timeout) ;
int
qps_dispatch_next(qps_selection qps) ;
diff --git a/lib/qpthreads.c b/lib/qpthreads.c
index 94ec37c0..5dd0cfc4 100644
--- a/lib/qpthreads.c
+++ b/lib/qpthreads.c
@@ -445,7 +445,6 @@ qpt_cond_t*
qpt_cond_init(qpt_cond_t* cv, enum qpt_cond_options opts)
{
pthread_condattr_t cond_attr ;
- int clock ;
int err ;
if (cv == NULL)
@@ -459,19 +458,12 @@ qpt_cond_init(qpt_cond_t* cv, enum qpt_cond_options opts)
switch(opts)
{
case qpt_cond_quagga:
- clock = QPT_COND_CLOCK_ID ;
- break ;
- case qpt_cond_realtime:
- clock = CLOCK_REALTIME ;
- break ;
- case qpt_cond_monotonic:
- clock = CLOCK_MONOTONIC ;
break ;
default:
zabort("Invalid qpt_cond option") ;
} ;
- err = pthread_condattr_setclock(&cond_attr, clock);
+ err = pthread_condattr_setclock(&cond_attr, QPT_COND_CLOCK_ID);
if (err != 0)
zabort_err("pthread_condattr_setclock failed", err) ;
@@ -508,6 +500,36 @@ qpt_cond_destroy(qpt_cond_t* cv, int free_cond)
return NULL ;
} ;
+/* Wait for given condition variable or time-out.
+ *
+ * Returns: wait succeeded (1 => success, 0 => timed-out).
+ *
+ * NB: timeout time is a qtime_mono_t (monotonic time).
+ *
+ * Has to check the return value, so zabort_errno if not EBUSY.
+ */
+
+int
+qpt_cond_timedwait(qpt_cond_t* cv, qpt_mutex_t* mx, qtime_mono_t timeout_time)
+{
+ struct timespec ts ;
+
+ if (QPT_COND_CLOCK_ID != CLOCK_MONOTONIC)
+ {
+ timeout_time = qt_clock_gettime(QPT_COND_CLOCK_ID)
+ + (timeout_time - qt_get_monotonic()) ;
+ } ;
+
+ int err = pthread_cond_timedwait(cv, mx, qtime2timespec(&ts, timeout_time)) ;
+ if (err == 0)
+ return 1 ; /* got condition */
+ if (err == ETIMEDOUT)
+ return 0 ; /* got time-out */
+
+ zabort_err("pthread_cond_timedwait failed", err) ;
+ /* crunch */
+} ;
+
/*==============================================================================
* Signal Handling.
*/
diff --git a/lib/qpthreads.h b/lib/qpthreads.h
index 1c51a9ee..5a442cc7 100644
--- a/lib/qpthreads.h
+++ b/lib/qpthreads.h
@@ -170,7 +170,7 @@ qpt_mutex_unlock(qpt_mutex_t* mx) ; /* do nothing if mx == NULL */
/*==============================================================================
* Condition Variable handling
*
- * Quagga's default clock for condition variables is QPT_COND_CLOCK_ID, which
+ * Quagga's clock for condition variables is QPT_COND_CLOCK_ID, which
* may be set elsewhere. If it is not set then it is set here to be:
*
* * CLOCK_MONOTONIC if available
@@ -179,30 +179,30 @@ qpt_mutex_unlock(qpt_mutex_t* mx) ; /* do nothing if mx == NULL */
* QPT_COND_CLOCK_MONOTONIC is set if CLOCK_MONOTONIC is used (and must be set
* if QPT_COND_CLOCK_ID is set elsewhere to something that is monotonic).
*
- * NB: qpt_cond_get_timeout_time uses QPT_COND_CLOCK_ID.
+ * NB: the time-out time passed to qpt_cond_timedwait() is a qtime_mono_t
+ * time (so based on qtime's monotonic time, which is CLOCK_MONOTONIC if
+ * that is available.
*
- * If a specific clock is required, it can be set... but the user of the
- * condition variable must take care to base time-out times on that clock.
+ * Otherwise, there is a conversion step from qtime_mono_t to whatever the
+ * timebase for the condition variable is.
*
* NB: static initialisation of condition variables is not supported, to avoid
* confusion between the standard default and Quagga's default.
*/
#ifndef QPT_COND_CLOCK_ID
-# ifndef HAVE_CLOCK_MONOTONIC
-# define QPT_COND_CLOCK_ID CLOCK_REALTIME
-# undef QPT_COND_CLOCK_MONOTONIC
-# else
+# ifdef HAVE_CLOCK_MONOTONIC
# define QPT_COND_CLOCK_ID CLOCK_MONOTONIC
# define QPT_COND_CLOCK_MONOTONIC 1
+# else
+# define QPT_COND_CLOCK_ID CLOCK_REALTIME
+# undef QPT_COND_CLOCK_MONOTONIC
# endif
#endif
enum qpt_cond_options
{
qpt_cond_quagga = 0x0000, /* Quagga's default */
- qpt_cond_realtime = 0x0001, /* standard default */
- qpt_cond_monotonic = 0x0002,
} ;
extern qpt_cond_t*
@@ -217,11 +217,8 @@ qpt_cond_destroy(qpt_cond_t* cv, int free_cond) ;
Inline void
qpt_cond_wait(qpt_cond_t* cv, qpt_mutex_t* mx) ;
-Inline qtime_t
-qpt_cond_get_timeout_time(qtime_t wait) ;
-
-Inline int
-qpt_cond_timedwait(qpt_cond_t* cv, qpt_mutex_t* mx, qtime_t tot) ;
+extern int
+qpt_cond_timedwait(qpt_cond_t* cv, qpt_mutex_t* mx, qtime_mono_t timeout_time) ;
Inline void
qpt_cond_signal(qpt_cond_t* cv) ;
@@ -319,44 +316,6 @@ qpt_cond_wait(qpt_cond_t* cv, qpt_mutex_t* mx)
#endif
} ;
-/* Get a time-out time (for use with qpt_cond_timedwait).
- *
- * Returns the current system time plus the given wait time.
- */
-
-Inline qtime_t
-qpt_cond_get_timeout_time(qtime_t wait)
-{
- return qt_clock_gettime(QPT_COND_CLOCK_ID) + wait ;
-} ;
-
-/* Wait for given condition variable or time-out.
- *
- * Returns: wait succeeded (1 => success, 0 => timed-out).
- *
- * The time-out is an *absolute* time expressed as a qtime_t.
- *
- * NB: qpt_cond_get_timeout_time() should be used to generate the required
- * time-out. That uses CLOCK_
- *
- * Has to check the return value, so zabort_errno if not EBUSY.
- */
-
-Inline int
-qpt_cond_timedwait(qpt_cond_t* cv, qpt_mutex_t* mx, qtime_t tot)
-{
- struct timespec ts ;
-
- int err = pthread_cond_timedwait(cv, mx, qtime2timespec(&ts, tot)) ;
- if (err == 0)
- return 1 ; /* got condition */
- if (err == ETIMEDOUT)
- return 0 ; /* got time-out */
-
- zabort_err("pthread_cond_timedwait failed", err) ;
- /* crunch */
-} ;
-
/* Signal given condition.
*
* Unless both NCHECK_QPTHREADS and NDEBUG are defined, checks that the
diff --git a/lib/qtime.c b/lib/qtime.c
index 2e881be3..3ec34a72 100644
--- a/lib/qtime.c
+++ b/lib/qtime.c
@@ -109,7 +109,7 @@ static int64_t times_clk_tcks = 0 ; /* sysconf(_SC_CLK_TCK) */
static qtime_t times_scale_q = 0 ; /* 10**9 / times_clk_tcks */
static qtime_t times_scale_r = 0 ; /* 10**9 % times_clk_tcks */
-qtime_t
+qtime_mono_t
qt_craft_monotonic(void) {
struct tms dummy ;
int64_t this_times_sample ;
diff --git a/lib/qtime.h b/lib/qtime.h
index 3f089f53..35e1a51b 100644
--- a/lib/qtime.h
+++ b/lib/qtime.h
@@ -53,6 +53,12 @@
typedef int64_t qtime_t ;
+typedef qtime_t qtime_real_t ; /* qtime_t value, realtime time-base */
+typedef qtime_t qtime_mono_t ; /* qtime_t value, monotonic time-base */
+
+typedef qtime_t qtime_tod_t ; /* qtime_t value, timeofday time-base... */
+ /* ...just in case != CLOCK_REALTIME ! */
+
/* A qtime_t second 123456789 -- nano-seconds */
#define QTIME_SECOND 1000000000
#define TIMESPEC_SECOND 1000000000
@@ -91,29 +97,38 @@ qtime2timeval(struct timeval* p_tv, qtime_t qt) ;
* a manufactured equivalent using times() -- see qt_craft_monotonic().
*/
-Inline qtime_t
+Inline qtime_real_t
qt_get_realtime(void) ; /* clock_gettime(CLOCK_REALTIME, ...) */
-Inline qtime_t
+Inline qtime_mono_t
+qt_add_realtime(qtime_t interval) ; /* qt_get_realtime() + interval */
+
+Inline qtime_mono_t
qt_get_monotonic(void) ; /* clock_gettime(CLOCK_MONOTONIC, ...) */
/* OR equivalent using times() */
+Inline qtime_mono_t
+qt_add_monotonic(qtime_t interval) ; /* qt_get_monotonic() + interval */
-Inline qtime_t /* monotonic time from CLOCK_REALTIME */
-qt_realtime2monotonic(qtime_t realtime) ;
-Inline qtime_t /* CLOCK_REALTIME from monotonic time */
-qt_monotonic2realtime(qtime_t monotonic) ;
+Inline qtime_mono_t /* monotonic time from CLOCK_REALTIME */
+qt_realtime2monotonic(qtime_real_t realtime) ;
+Inline qtime_real_t /* CLOCK_REALTIME from monotonic time */
+qt_monotonic2realtime(qtime_mono_t monotonic) ;
/* Function to manufacture a monotonic clock. */
-extern qtime_t qt_craft_monotonic(void) ;
+extern qtime_mono_t
+qt_craft_monotonic(void) ;
/* These are provided just in case gettimeofday() != CLOCK_REALTIME */
-Inline qtime_t
+Inline qtime_tod_t
qt_get_timeofday(void) ; /* gettimeofday(&tv, NULL) */
-Inline qtime_t /* monotonic time from timeofday */
-qt_timeofday2monotonic(qtime_t timeofday) ;
-Inline qtime_t /* timeofday from monotonic time */
-qt_monotonic2timeofday(qtime_t monotonic) ;
+Inline qtime_tod_t
+qt_add_timeofday(qtime_t interval) ; /* qt_get_timeofday() + interval */
+
+Inline qtime_mono_t /* monotonic time from timeofday */
+qt_timeofday2monotonic(qtime_tod_t timeofday) ;
+Inline qtime_tod_t /* timeofday from monotonic time */
+qt_monotonic2timeofday(qtime_mono_t monotonic) ;
/*==============================================================================
* Inline conversion functions
@@ -196,34 +211,32 @@ qt_clock_gettime(clockid_t clock_id)
return timespec2qtime(&ts) ;
} ;
-/* gettimeofday(&tv, NULL) -- returning qtime_t value
- */
-Inline qtime_t
-qt_get_timeofday(void)
-{
- struct timeval tv ;
- gettimeofday(&tv, NULL) ;
- return timeval2qtime(&tv) ;
-}
-
/* clock_gettime(CLOCK_REALTIME, ...) -- returning qtime_t value
*
* While possibility of error is essentially theoretical, must treat it as a
* FATAL error -- cannot continue with broken time value !
*/
-Inline qtime_t
+Inline qtime_real_t
qt_get_realtime(void)
{
return qt_clock_gettime(CLOCK_REALTIME) ;
} ;
+/* qt_get_realtime() + interval
+ */
+Inline qtime_real_t
+qt_add_realtime(qtime_t interval)
+{
+ return qt_get_realtime() + interval;
+} ;
+
/* clock_gettime(CLOCK_MONOTONIC, ...) OR qt_craft_monotonic()
* -- returning qtime_t value
*
* While possibility of error is essentially theoretical, must treat it as a
* FATAL error -- cannot continue with broken time value !
*/
-Inline qtime_t
+Inline qtime_mono_t
qt_get_monotonic(void)
{
#ifdef HAVE_CLOCK_MONOTONIC
@@ -233,34 +246,60 @@ qt_get_monotonic(void)
#endif
} ;
+/* qt_get_monotonic() + interval
+ */
+Inline qtime_mono_t
+qt_add_monotonic(qtime_t interval)
+{
+ return qt_get_monotonic() + interval;
+} ;
+
+/* gettimeofday(&tv, NULL) -- returning qtime_t value
+ */
+Inline qtime_tod_t
+qt_get_timeofday(void)
+{
+ struct timeval tv ;
+ gettimeofday(&tv, NULL) ;
+ return timeval2qtime(&tv) ;
+}
+
+/* qt_get_timeofday() + interval
+ */
+Inline qtime_tod_t
+qt_add_timeofday(qtime_t interval)
+{
+ return qt_get_timeofday() + interval;
+} ;
+
/*==============================================================================
* Conversion between realtime/timeofday and monotonic
*/
/* Convert a CLOCK_REALTIME time to our local monotonic time. */
-Inline qtime_t
-qt_realtime2monotonic(qtime_t realtime)
+Inline qtime_mono_t
+qt_realtime2monotonic(qtime_real_t realtime)
{
return qt_get_monotonic() + (realtime - qt_get_realtime()) ;
} ;
/* Convert a local monotonic time to CLOCK_REALTIME time. */
-Inline qtime_t
-qt_monotonic2realtime(qtime_t monotonic)
+Inline qtime_real_t
+qt_monotonic2realtime(qtime_mono_t monotonic)
{
return qt_get_realtime() + (monotonic - qt_get_monotonic()) ;
} ;
/* Convert a gettimeofday() time to our local monotonic time. */
-Inline qtime_t
-qt_timeofday2monotonic(qtime_t timeofday)
+Inline qtime_mono_t
+qt_timeofday2monotonic(qtime_tod_t timeofday)
{
return qt_get_monotonic() + (timeofday - qt_get_timeofday()) ;
} ;
/* Convert a local monotonic time to gettimeofday() time. */
-Inline qtime_t
-qt_monotonic2timeofday(qtime_t monotonic)
+Inline qtime_tod_t
+qt_monotonic2timeofday(qtime_mono_t monotonic)
{
return qt_get_timeofday() + (monotonic - qt_get_monotonic()) ;
} ;
diff --git a/lib/qtimers.c b/lib/qtimers.c
index f4959983..d4aff6ec 100644
--- a/lib/qtimers.c
+++ b/lib/qtimers.c
@@ -1,4 +1,4 @@
-/* Quagga timers support -- header
+/* Quagga timers support -- functions
* Copyright (C) 2009 Chris Hall (GMCH), Highwayman
*
* This file is part of GNU Zebra.
@@ -52,9 +52,6 @@
*
* The time base for qtimers is the monotonic time provided in qtime.c/.h.
*
- * The qtimer_time_now(), qtimer_time_future(), timer_time_from_realtime(),
- * qtimer_time_from_timeofday() functions return qtimer times.
- *
* Action Functions
* ----------------
*
@@ -116,8 +113,8 @@ qtimer_pile_init_new(qtimer_pile qtp)
* empty, or the top entry times out after the maximum time, then the maximum
* is returned.
*/
-qtime_t
-qtimer_pile_top_time(qtimer_pile qtp, qtime_t max_time)
+qtime_mono_t
+qtimer_pile_top_time(qtimer_pile qtp, qtime_mono_t max_time)
{
qtimer qtr = heap_top_item(&qtp->timers) ;
@@ -138,7 +135,7 @@ qtimer_pile_top_time(qtimer_pile qtp, qtime_t max_time)
* false <=> nothing to do (and nothing done).
*/
int
-qtimer_pile_dispatch_next(qtimer_pile qtp, qtime_t upto)
+qtimer_pile_dispatch_next(qtimer_pile qtp, qtime_mono_t upto)
{
qtimer qtr ;
@@ -295,7 +292,7 @@ qtimer_set_info(qtimer qtr, void* timer_info)
* It is an error to set a timer which has a NULL action.
*/
void
-qtimer_set(qtimer qtr, qtime_t when, qtimer_action* action)
+qtimer_set(qtimer qtr, qtime_mono_t when, qtimer_action* action)
{
qtimer_pile qtp ;
diff --git a/lib/qtimers.h b/lib/qtimers.h
index a4d4a1c3..3a774b38 100644
--- a/lib/qtimers.h
+++ b/lib/qtimers.h
@@ -44,7 +44,7 @@
typedef struct qtimer* qtimer ;
typedef struct qtimer_pile* qtimer_pile ;
-typedef void (qtimer_action)(qtimer qtr, void* timer_info, qtime_t when) ;
+typedef void (qtimer_action)(qtimer qtr, void* timer_info, qtime_mono_t when) ;
enum qtimer_state {
qtr_state_inactive = 0,
@@ -63,7 +63,7 @@ struct qtimer
qtimer_state_t state ;
- qtime_t time ;
+ qtime_mono_t time ;
qtimer_action* action ;
void* timer_info ;
} ;
@@ -81,10 +81,10 @@ qtimer_pile
qtimer_pile_init_new(qtimer_pile qtp) ;
int
-qtimer_pile_dispatch_next(qtimer_pile qtp, qtime_t upto) ;
+qtimer_pile_dispatch_next(qtimer_pile qtp, qtime_mono_t upto) ;
-qtime_t
-qtimer_pile_top_time(qtimer_pile qtp, qtime_t max_time) ;
+qtime_mono_t
+qtimer_pile_top_time(qtimer_pile qtp, qtime_mono_t max_time) ;
qtimer
qtimer_pile_ream(qtimer_pile qtp, int free_structure) ;
@@ -94,18 +94,6 @@ qtimer_pile_ream(qtimer_pile qtp, int free_structure) ;
/* Ream out qtimer pile but keep the qtimer structure. */
#define qtimer_pile_ream_keep(qtp) qtimer_pile_ream(qtp, 0)
-Inline qtime_t
-qtimer_time_now() ;
-
-Inline qtime_t
-qtimer_time_future(qtime_t interval) ;
-
-Inline qtime_t
-qtimer_time_from_realtime(qtime_t realtime) ;
-
-Inline qtime_t
-qtimer_time_from_timeofday(qtime_t timeofday) ;
-
qtimer
qtimer_init_new(qtimer qtr, qtimer_pile qtp,
qtimer_action* action, void* timer_info) ;
@@ -122,7 +110,7 @@ void
qtimer_free(qtimer qtr) ;
void
-qtimer_set(qtimer qtr, qtime_t when, qtimer_action* action) ;
+qtimer_set(qtimer qtr, qtime_mono_t when, qtimer_action* action) ;
void
qtimer_unset(qtimer qtr) ;
@@ -130,45 +118,13 @@ qtimer_unset(qtimer qtr) ;
Inline void
qtimer_add(qtimer qtr, qtime_t interval, qtimer_action* action) ;
-Inline qtime_t
+Inline qtime_mono_t
qtimer_get(qtimer qtr) ;
/*==============================================================================
* Inline functions
*/
-/* The current time according to the qtimer time-base (monotonic time).
- */
-Inline qtime_t
-qtimer_time_now()
-{
- return qt_get_monotonic() ;
-}
-
-/* What the qtimer time will be 'interval' qtime_t units from now..
- */
-Inline qtime_t
-qtimer_time_future(qtime_t interval)
-{
- return qtimer_time_now() + interval ;
-} ;
-
-/* Get a qtimer time from a CLOCK_REALTIME time
- */
-Inline qtime_t
-qtimer_time_from_realtime(qtime_t realtime)
-{
- return qt_realtime2monotonic(realtime) ;
-} ;
-
-/* Get a qtimer time from a gettimeofday() time (in case != CLOCK_REALTIME)
- */
-Inline qtime_t
-qtimer_time_from_timeofday(qtime_t timeofday)
-{
- return qt_timeofday2monotonic(timeofday) ;
-} ;
-
/* Set given timer to given time later than *its* current time.
*/
Inline void
@@ -179,7 +135,7 @@ qtimer_add(qtimer qtr, qtime_t interval, qtimer_action* action)
/* Get the given timer's time.
*/
-Inline qtime_t
+Inline qtime_mono_t
qtimer_get(qtimer qtr)
{
return qtr->time ;
diff --git a/lib/vty.c b/lib/vty.c
index 782575a6..6a307c6b 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -2996,7 +2996,7 @@ vty_event_r (enum event event, int sock, struct vty *vty)
/* Time out treatment. */
if (vty->v_timeout)
{
- qtimer_set(vty->qtr, qtimer_time_future(QTIME(vty->v_timeout)), NULL) ;
+ qtimer_set(vty->qtr, qt_add_monotonic(QTIME(vty->v_timeout)), NULL) ;
}
break;
case VTY_WRITE:
@@ -3005,7 +3005,7 @@ vty_event_r (enum event event, int sock, struct vty *vty)
case VTY_TIMEOUT_RESET:
if (vty->v_timeout)
{
- qtimer_set(vty->qtr, qtimer_time_future(QTIME(vty->v_timeout)), NULL) ;
+ qtimer_set(vty->qtr, qt_add_monotonic(QTIME(vty->v_timeout)), NULL) ;
}
else
{