From 6c0aaa4253f7cfde32eeac2fb0db2bc6b5ae7551 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 12 Jul 2007 09:04:54 +0000 Subject: [PATCH] Add TIM_mono() and TIM_real() which return double representations of timestamps on a monotonic and the UTC timescales respectively. Doubles are much more convenient than timespecs for comparisons etc. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1668 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/include/libvarnish.h | 2 ++ varnish-cache/lib/libvarnish/time.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/varnish-cache/include/libvarnish.h b/varnish-cache/include/libvarnish.h index 981fb309..7022d3e4 100644 --- a/varnish-cache/include/libvarnish.h +++ b/varnish-cache/include/libvarnish.h @@ -47,6 +47,8 @@ uint32_t crc32_l(const void *p1, unsigned l); /* from libvarnish/time.c */ void TIM_format(time_t t, char *p); time_t TIM_parse(const char *p); +double TIM_mono(void); +double TIM_real(void); /* from libvarnish/version.c */ void varnish_version(const char *); diff --git a/varnish-cache/lib/libvarnish/time.c b/varnish-cache/lib/libvarnish/time.c index 855ac467..66c4a251 100644 --- a/varnish-cache/lib/libvarnish/time.c +++ b/varnish-cache/lib/libvarnish/time.c @@ -50,8 +50,30 @@ #include #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "libvarnish.h" +double +TIM_mono(void) +{ + struct timespec ts; + + assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); + return (ts.tv_sec + 1e-9 * ts.tv_nsec); +} + +double +TIM_real(void) +{ + struct timespec ts; + + assert(clock_gettime(CLOCK_REALTIME, &ts) == 0); + return (ts.tv_sec + 1e-9 * ts.tv_nsec); +} + void TIM_format(time_t t, char *p) { -- 2.39.5