From 363bf44a353ca0ce7e9d48476fb187d8da037483 Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Fri, 5 Jun 2020 17:56:13 -0400 Subject: util/time: move `timespec_sub` to time utilities --- util/log.c | 12 +----------- util/time.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'util') diff --git a/util/log.c b/util/log.c index 17655d30..cbec3e86 100644 --- a/util/log.c +++ b/util/log.c @@ -8,6 +8,7 @@ #include #include #include +#include "util/time.h" static bool colored = true; static enum wlr_log_importance log_importance = WLR_ERROR; @@ -27,17 +28,6 @@ static const char *verbosity_headers[] = { [WLR_DEBUG] = "[DEBUG]", }; -static void timespec_sub(struct timespec *r, const struct timespec *a, - const struct timespec *b) { - const long NSEC_PER_SEC = 1000000000; - r->tv_sec = a->tv_sec - b->tv_sec; - r->tv_nsec = a->tv_nsec - b->tv_nsec; - if (r->tv_nsec < 0) { - r->tv_sec--; - r->tv_nsec += NSEC_PER_SEC; - } -} - static void init_start_time(void) { if (start_time.tv_sec >= 0) { return; diff --git a/util/time.c b/util/time.c index a47fc613..aed577de 100644 --- a/util/time.c +++ b/util/time.c @@ -4,6 +4,8 @@ #include "util/time.h" +const long NSEC_PER_SEC = 1000000000; + int64_t timespec_to_msec(const struct timespec *a) { return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; } @@ -13,3 +15,13 @@ uint32_t get_current_time_msec(void) { clock_gettime(CLOCK_MONOTONIC, &now); return timespec_to_msec(&now); } + +void timespec_sub(struct timespec *r, const struct timespec *a, + const struct timespec *b) { + r->tv_sec = a->tv_sec - b->tv_sec; + r->tv_nsec = a->tv_nsec - b->tv_nsec; + if (r->tv_nsec < 0) { + r->tv_sec--; + r->tv_nsec += NSEC_PER_SEC; + } +} -- cgit v1.2.3