]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Use clock_gettime instead of gettimeofday
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 6 Aug 2017 17:09:15 +0000 (18:09 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 6 Aug 2017 17:09:15 +0000 (18:09 +0100)
src/libutil/util.c
src/libutil/util.h

index c8c446138e1d48426cddd57c251f62d44ee4ee16..54cacef44a9318cfd74cff379183fdac1e36cdd5 100644 (file)
@@ -1902,14 +1902,21 @@ gdouble
 rspamd_get_calendar_ticks (void)
 {
        gdouble res;
+#ifdef HAVE_CLOCK_GETTIME
+       struct timespec ts;
+
+       clock_gettime (CLOCK_REALTIME, &ts);
+       res = ts_to_double (&ts);
+#else
        struct timeval tv;
 
        if (gettimeofday (&tv, NULL) == 0) {
-               res = (gdouble)tv.tv_sec + tv.tv_usec / 1e6f;
+               res = tv_to_double (&tv);
        }
        else {
                res = time (NULL);
        }
+#endif
 
        return res;
 }
index f07d166c5bff3c8e61c78a84935e4daee19e0e43..9f42d6c924353b9b4975485cb580a7e892235253 100644 (file)
@@ -207,6 +207,7 @@ void g_ptr_array_insert (GPtrArray *array, gint index_, gpointer data);
 #define tv_to_double(tv) ((double)(tv)->tv_sec + (tv)->tv_usec / 1.0e6)
 #define ts_to_usec(ts) ((ts)->tv_sec * 1000000LLU +                                                    \
        (ts)->tv_nsec / 1000LLU)
+#define ts_to_double(tv) ((double)(tv)->tv_sec + (tv)->tv_nsec / 1.0e9)
 
 /**
  * Try to allocate a file on filesystem (using fallocate or posix_fallocate)