r1668 - in trunk/varnish-cache: include lib/libvarnish

phk at projects.linpro.no phk at projects.linpro.no
Thu Jul 12 11:04:55 CEST 2007


Author: phk
Date: 2007-07-12 11:04:54 +0200 (Thu, 12 Jul 2007)
New Revision: 1668

Modified:
   trunk/varnish-cache/include/libvarnish.h
   trunk/varnish-cache/lib/libvarnish/time.c
Log:
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.



Modified: trunk/varnish-cache/include/libvarnish.h
===================================================================
--- trunk/varnish-cache/include/libvarnish.h	2007-07-10 21:30:47 UTC (rev 1667)
+++ trunk/varnish-cache/include/libvarnish.h	2007-07-12 09:04:54 UTC (rev 1668)
@@ -47,6 +47,8 @@
 /* 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 *);

Modified: trunk/varnish-cache/lib/libvarnish/time.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/time.c	2007-07-10 21:30:47 UTC (rev 1667)
+++ trunk/varnish-cache/lib/libvarnish/time.c	2007-07-12 09:04:54 UTC (rev 1668)
@@ -50,8 +50,30 @@
 #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)
 {




More information about the varnish-commit mailing list