aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-09-19 22:34:12 -0500
committerCharles Kerr <charles.kerr@canonical.com>2012-09-19 22:34:12 -0500
commit1a48f285e56954ba589cb4cb12d0fa7c0da558e8 (patch)
treeb2ccc2a449155308b553a453712ae6e6bca9de39
parent6145a631d5d1095ac937d28ba812f7e3cb315c1c (diff)
downloadayatana-indicator-datetime-1a48f285e56954ba589cb4cb12d0fa7c0da558e8.tar.gz
ayatana-indicator-datetime-1a48f285e56954ba589cb4cb12d0fa7c0da558e8.tar.bz2
ayatana-indicator-datetime-1a48f285e56954ba589cb4cb12d0fa7c0da558e8.zip
clocks don't skew very often, so let's reduce the frequency that we test for this.
-rw-r--r--src/datetime-service.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c
index 88689b7..d2a9a63 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -1181,16 +1181,22 @@ day_timer_reset (void)
return;
}
-static guint second_timer = 0;
+enum {
+ /* how often to check for clock skew */
+ SKEW_CHECK_INTERVAL_SEC = 10,
+
+ SKEW_DIFF_THRESHOLD_SEC = SKEW_CHECK_INTERVAL_SEC + 5
+};
static gboolean
-second_timer_func (gpointer unused G_GNUC_UNUSED)
+skew_check_timer_func (gpointer unused G_GNUC_UNUSED)
{
- static time_t prev_time =0;
+ static time_t prev_time = 0;
const time_t cur_time = time (NULL);
+ const double diff_sec = fabs (difftime (cur_time, prev_time));
- if (prev_time && (fabs (difftime (cur_time, prev_time)) > 5)) {
- g_debug (G_STRLOC" clock skew detected");
+ if (prev_time && (diff_sec > SKEW_DIFF_THRESHOLD_SEC)) {
+ g_debug (G_STRLOC" clock skew detected (%.0f seconds)", diff_sec);
on_clock_skew ();
}
@@ -1458,7 +1464,9 @@ main (int argc, char ** argv)
day_timer_reset();
/* Set up the second timer */
- second_timer = g_timeout_add_seconds_full (G_PRIORITY_LOW, 1, second_timer_func, NULL, NULL);
+ g_timeout_add_seconds (SKEW_CHECK_INTERVAL_SEC,
+ skew_check_timer_func,
+ NULL);
/* And watch for system resumes */
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,