mc_timer: use g_get_real_time() instead of gettimeofday().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2020-09-06 11:03:51 +03:00
parent 63aba8f7e2
commit 3143196247

View File

@ -29,8 +29,6 @@
#include <config.h> #include <config.h>
#include <sys/time.h>
#include "lib/global.h" #include "lib/global.h"
#include "lib/timer.h" #include "lib/timer.h"
@ -69,11 +67,9 @@ mc_timer_t *
mc_timer_new (void) mc_timer_new (void)
{ {
mc_timer_t *timer; mc_timer_t *timer;
struct timeval tv;
timer = g_new (mc_timer_t, 1); timer = g_new (mc_timer_t, 1);
gettimeofday (&tv, NULL); timer->start = (guint64) g_get_real_time ();
timer->start = (guint64) tv.tv_sec * G_USEC_PER_SEC + (guint64) tv.tv_usec;
return timer; return timer;
} }
@ -104,11 +100,7 @@ mc_timer_destroy (mc_timer_t * timer)
guint64 guint64
mc_timer_elapsed (const mc_timer_t * timer) mc_timer_elapsed (const mc_timer_t * timer)
{ {
struct timeval tv; return ((guint64) g_get_real_time () - timer->start);
gettimeofday (&tv, NULL);
return ((guint64) tv.tv_sec * G_USEC_PER_SEC + (guint64) tv.tv_usec - timer->start);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */