diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2020-02-16 21:08:16 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2020-02-16 21:08:16 +0000 |
commit | 9fe06a0df04dabbe95e4e58c01f8ba4af6a459dc (patch) | |
tree | 01b36962e9cd5989c02d793a9d0bbdb8a4c8f2cf | |
parent | 56cab91b719626fe27dcf63e9df871a8d75b2b0c (diff) |
unravel isc_time_compare
OK millert
-rw-r--r-- | usr.bin/dig/lib/isc/log.c | 6 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/timer.c | 32 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/unix/include/isc/time.h | 18 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/unix/time.c | 18 |
4 files changed, 16 insertions, 58 deletions
diff --git a/usr.bin/dig/lib/isc/log.c b/usr.bin/dig/lib/isc/log.c index 6e50109fb2e..afdc560064e 100644 --- a/usr.bin/dig/lib/isc/log.c +++ b/usr.bin/dig/lib/isc/log.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: log.c,v 1.9 2020/02/16 21:06:15 florian Exp $ */ +/* $Id: log.c,v 1.10 2020/02/16 21:08:15 florian Exp $ */ /*! \file * \author Principal Authors: DCL */ @@ -1000,8 +1000,8 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, message = ISC_LIST_HEAD(lctx->messages); while (message != NULL) { - if (isc_time_compare(&message->time, - &oldest) < 0) { + if (timespeccmp(&message->time, + &oldest, <)) { /* * This message is older * than the duplicate_interval, diff --git a/usr.bin/dig/lib/isc/timer.c b/usr.bin/dig/lib/isc/timer.c index f4324d0794b..46ce142a111 100644 --- a/usr.bin/dig/lib/isc/timer.c +++ b/usr.bin/dig/lib/isc/timer.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: timer.c,v 1.15 2020/02/16 21:07:33 florian Exp $ */ +/* $Id: timer.c,v 1.16 2020/02/16 21:08:15 florian Exp $ */ /*! \file */ @@ -101,7 +101,6 @@ schedule(isc__timer_t *timer, struct timespec *now, isc_boolean_t signal_ok) { isc_result_t result; isc__timermgr_t *manager; struct timespec due; - int cmp; /*! * Note: the caller must ensure locking. @@ -124,19 +123,12 @@ schedule(isc__timer_t *timer, struct timespec *now, isc_boolean_t signal_ok) { /* * Already scheduled. */ - cmp = isc_time_compare(&due, &timer->due); + if (timespeccmp(&due, &timer->due, <)) + isc_heap_increased(manager->heap, timer->index); + else if (timespeccmp(&due, &timer->due, >)) + isc_heap_decreased(manager->heap, timer->index); + timer->due = due; - switch (cmp) { - case -1: - isc_heap_increased(manager->heap, timer->index); - break; - case 1: - isc_heap_decreased(manager->heap, timer->index); - break; - case 0: - /* Nothing to do. */ - break; - } } else { timer->due = due; result = isc_heap_insert(manager->heap, timer); @@ -153,8 +145,7 @@ schedule(isc__timer_t *timer, struct timespec *now, isc_boolean_t signal_ok) { * the current "next" timer. We do this either by waking up the * run thread, or explicitly setting the value in the manager. */ - if (timer->index == 1 && - isc_time_compare(&timer->due, &manager->due) < 0) + if (timer->index == 1 && timespeccmp(&timer->due, &manager->due, <)) manager->due = timer->due; return (ISC_R_SUCCESS); @@ -402,12 +393,11 @@ dispatch(isc__timermgr_t *manager, struct timespec *now) { while (manager->nscheduled > 0 && !done) { timer = isc_heap_element(manager->heap, 1); INSIST(timer != NULL); - if (isc_time_compare(now, &timer->due) >= 0) { + if (timespeccmp(now, &timer->due, >=)) { idle = ISC_FALSE; - if (timespecisset(&timer->idle) && - isc_time_compare(now, - &timer->idle) >= 0) { + if (timespecisset(&timer->idle) && timespeccmp(now, + &timer->idle, >=)) { idle = ISC_TRUE; } if (idle) { @@ -471,7 +461,7 @@ sooner(void *v1, void *v2) { REQUIRE(VALID_TIMER(t1)); REQUIRE(VALID_TIMER(t2)); - if (isc_time_compare(&t1->due, &t2->due) < 0) + if (timespeccmp(&t1->due, &t2->due, <)) return (ISC_TRUE); return (ISC_FALSE); } diff --git a/usr.bin/dig/lib/isc/unix/include/isc/time.h b/usr.bin/dig/lib/isc/unix/include/isc/time.h index b65e992682b..686d54ed3ea 100644 --- a/usr.bin/dig/lib/isc/unix/include/isc/time.h +++ b/usr.bin/dig/lib/isc/unix/include/isc/time.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: time.h,v 1.9 2020/02/16 21:07:33 florian Exp $ */ +/* $Id: time.h,v 1.10 2020/02/16 21:08:15 florian Exp $ */ #ifndef ISC_TIME_H #define ISC_TIME_H 1 @@ -52,22 +52,6 @@ isc_time_now(struct timespec *t); * Getting the time from the system failed. */ -int -isc_time_compare(const struct timespec *t1, const struct timespec *t2); -/*%< - * Compare the times referenced by 't1' and 't2' - * - * Requires: - * - *\li 't1' and 't2' are valid pointers. - * - * Returns: - * - *\li -1 t1 < t2 (comparing times, not pointers) - *\li 0 t1 = t2 - *\li 1 t1 > t2 - */ - isc_result_t isc_time_add(const struct timespec *t, const struct timespec *i, struct timespec *result); /*%< diff --git a/usr.bin/dig/lib/isc/unix/time.c b/usr.bin/dig/lib/isc/unix/time.c index 4b3658c3fdb..4d63835291c 100644 --- a/usr.bin/dig/lib/isc/unix/time.c +++ b/usr.bin/dig/lib/isc/unix/time.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: time.c,v 1.12 2020/02/16 21:07:33 florian Exp $ */ +/* $Id: time.c,v 1.13 2020/02/16 21:08:15 florian Exp $ */ /*! \file */ @@ -58,22 +58,6 @@ isc_time_now(struct timespec *t) { return (ISC_R_SUCCESS); } -int -isc_time_compare(const struct timespec *t1, const struct timespec *t2) { - REQUIRE(t1 != NULL && t2 != NULL); - INSIST(t1->tv_nsec < NS_PER_S && t2->tv_nsec < NS_PER_S); - - if (t1->tv_sec < t2->tv_sec) - return (-1); - if (t1->tv_sec > t2->tv_sec) - return (1); - if (t1->tv_nsec < t2->tv_nsec) - return (-1); - if (t1->tv_nsec > t2->tv_nsec) - return (1); - return (0); -} - isc_result_t isc_time_add(const struct timespec *t, const struct timespec *i, struct timespec *result) { |