]> err.no Git - varnish/commitdiff
Add TIM_mono() and TIM_real() which return double representations of
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 12 Jul 2007 09:04:54 +0000 (09:04 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 12 Jul 2007 09:04:54 +0000 (09:04 +0000)
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
varnish-cache/lib/libvarnish/time.c

index 981fb309a5a9fc44225f0c2b9e64439230d3470f..7022d3e4620a71eb7b56db46229a85f44d148029 100644 (file)
@@ -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 *);
index 855ac467909de0c5a0b84789fa50f65a19bf3162..66c4a251f7fcfe186ca89b7dbaa958a27225a80d 100644 (file)
 #include <string.h>
 #include <time.h>
 
+#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)
 {