[gnome-keyring] gkm-timer: Use monotonic time exclusively



commit 1864f1e14bfd41a51fac8324cac8cbd2b31cc3cc
Author: Daiki Ueno <dueno src gnome org>
Date:   Thu Mar 1 17:06:29 2018 +0100

    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

 pkcs11/gkm/gkm-timer.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)
---
diff --git a/pkcs11/gkm/gkm-timer.c b/pkcs11/gkm/gkm-timer.c
index 918b5b3..5052d6d 100644
--- a/pkcs11/gkm/gkm-timer.c
+++ b/pkcs11/gkm/gkm-timer.c
@@ -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;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]