From: Florian Forster Date: Sun, 31 Oct 2010 11:51:02 +0000 (+0100) Subject: src/utils_time.h: Add macros for converting to "struct timespec" .. X-Git-Tag: collectd-5.0.0-beta0~19^2~19 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9e79bea7d3f158f2fd39dda8a413843a7bec819b;p=collectd.git src/utils_time.h: Add macros for converting to "struct timespec" .. .. and "struct timeval". --- diff --git a/src/utils_time.h b/src/utils_time.h index fecf5447..0aa4fce6 100644 --- a/src/utils_time.h +++ b/src/utils_time.h @@ -41,11 +41,22 @@ typedef uint64_t cdtime_t; #define CDTIME_T_TO_DOUBLE(t) (((double) (t)) / 1073741824.0) #define DOUBLE_TO_CDTIME_T(d) ((cdtime_t) ((d) * 1073741824.0)) -#define US_TO_CDTIME_T(us) ((cdtime_t) (((double) (us)) * 1073.741824)) -#define NS_TO_CDTIME_T(ns) ((cdtime_t) (((double) (ns)) * 1.073741824)) +#define US_TO_CDTIME_T(us) ((cdtime_t) (((double) (us)) * 1073.741824)) +#define CDTIME_T_TO_US(t) ((suseconds_t) (((double) (t)) / 1073.741824)) +#define NS_TO_CDTIME_T(ns) ((cdtime_t) (((double) (ns)) * 1.073741824)) +#define CDTIME_T_TO_NS(t) ((long) (((double) (t)) / 1.073741824)) +#define CDTIME_T_TO_TIMEVAL(t) { \ + CDTIME_T_TO_TIME_T (t), \ + CDTIME_T_TO_US (t % 1073741824) \ +} #define TIMEVAL_TO_CDTIME_T(tv) (TIME_T_TO_CDTIME_T ((tv).tv_sec) \ + US_TO_CDTIME_T ((tv).tv_usec)) + +#define CDTIME_T_TO_TIMESPEC(t) { \ + CDTIME_T_TO_TIME_T (t), \ + CDTIME_T_TO_NS (t % 1073741824) \ +} #define TIMESPEC_TO_CDTIME_T(ts) (TIME_T_TO_CDTIME_T ((ts).tv_sec) \ + NS_TO_CDTIME_T ((ts).tv_nsec))