From 2278204ddd3ceba1b8a0217b63372db7549cd8b8 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 18 Aug 2013 00:27:33 +1000 Subject: [PATCH] Provide a us_to_timeval helper function. --- util.c | 6 ++++++ util.h | 1 + 2 files changed, 7 insertions(+) diff --git a/util.c b/util.c index ef87dc3f..61591dcd 100644 --- a/util.c +++ b/util.c @@ -902,6 +902,12 @@ void timeval_to_spec(struct timespec *spec, const struct timeval *val) spec->tv_nsec = val->tv_usec * 1000; } +void us_to_timeval(struct timeval *val, int64_t us) +{ + val->tv_sec = us / 1000000; + val->tv_usec = us - (val->tv_sec * 1000000); +} + /* Returns the microseconds difference between end and start times as a double */ double us_tdiff(struct timeval *end, struct timeval *start) { diff --git a/util.h b/util.h index b5732200..3cc7ffed 100644 --- a/util.h +++ b/util.h @@ -80,6 +80,7 @@ bool time_less(struct timeval *a, struct timeval *b); void copy_time(struct timeval *dest, const struct timeval *src); void timespec_to_val(struct timeval *val, const struct timespec *spec); void timeval_to_spec(struct timespec *spec, const struct timeval *val); +void us_to_timeval(struct timeval *val, int64_t us); double us_tdiff(struct timeval *end, struct timeval *start); double tdiff(struct timeval *end, struct timeval *start); bool stratum_send(struct pool *pool, char *s, ssize_t len);