Commit 1864f1e1 authored by Daiki Ueno's avatar Daiki Ueno

gkm-timer: Use monotonic time exclusively

Previously, it used g_get_real_time(), g_get_current_time(), and
g_get_monotonic_time() in a mixed manner.  To measure the elapsed
time, it would be sufficient to use g_get_monotonic_time() only.

https://bugzilla.gnome.org/show_bug.cgi?id=791932
parent 5d8326ea
......@@ -27,7 +27,7 @@
#include <glib.h>
struct _GkmTimer {
glong when;
gint64 when;
GMutex *mutex;
gpointer identifier;
GkmTimerFunc callback;
......@@ -69,8 +69,7 @@ timer_thread_func (gpointer unused)
}
if (timer->when) {
gint64 when = ((gint64)timer->when) * G_TIME_SPAN_SECOND;
gint64 offset = when - g_get_real_time ();
gint64 offset = timer->when - g_get_monotonic_time ();
if (offset > 0) {
g_cond_wait_until (timer_cond, &timer_mutex, g_get_monotonic_time () + offset);
continue;
......@@ -165,15 +164,12 @@ GkmTimer*
gkm_timer_start (GkmModule *module, glong seconds, GkmTimerFunc callback, gpointer user_data)
{
GkmTimer *timer;
GTimeVal tv;
g_return_val_if_fail (callback, NULL);
g_return_val_if_fail (timer_queue, NULL);
g_get_current_time (&tv);
timer = g_slice_new (GkmTimer);
timer->when = seconds + tv.tv_sec;
timer->when = g_get_monotonic_time () + seconds * G_TIME_SPAN_SECOND;
timer->callback = callback;
timer->user_data = user_data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment