[gnome-panel] [clock] Avoid unnecessary wakeups when monitoring non-existing files
- From: Vincent Untz <vuntz src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-panel] [clock] Avoid unnecessary wakeups when monitoring non-existing files
- Date: Thu, 14 Jan 2010 01:51:37 +0000 (UTC)
commit b0d742da06df69fd70fb38af927cada4cebcfca3
Author: Vincent Untz <vuntz gnome org>
Date: Thu Jan 14 02:49:14 2010 +0100
[clock] Avoid unnecessary wakeups when monitoring non-existing files
If the parent directory of a timezone-related file doesn't exist on the
system, then it means the file is not useful to determine the timezone
on this system.
Since gio doesn't handle well monitoring files in non-existing
directories (it polls every other second), this should avoid unnecessary
wakeups.
https://bugzilla.gnome.org/show_bug.cgi?id=580357
applets/clock/system-timezone.c | 26 +++++++++++++++++++++-----
1 files changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/applets/clock/system-timezone.c b/applets/clock/system-timezone.c
index bcd7f4a..336f5a9 100644
--- a/applets/clock/system-timezone.c
+++ b/applets/clock/system-timezone.c
@@ -190,12 +190,27 @@ system_timezone_constructor (GType type,
priv->env_tz = g_strdup (g_getenv ("TZ"));
for (i = 0; i < CHECK_NB; i++) {
- GFile *file;
+ GFile *file;
+ GFile *parent;
+ GFileType parent_type;
file = g_file_new_for_path (files_to_check[i]);
- priv->monitors[i] = g_file_monitor_file (file,
- G_FILE_MONITOR_NONE,
- NULL, NULL);
+
+ parent = g_file_get_parent (file);
+ parent_type = g_file_query_file_type (parent, G_FILE_QUERY_INFO_NONE, NULL);
+ g_object_unref (parent);
+
+ /* We don't try to monitor the file if the parent directory
+ * doesn't exist: this means we're on a system where this file
+ * is not useful to determine the system timezone.
+ * Since gio does not monitor file in non-existing directories
+ * in a clever way (as of gio 2.22, it just polls every other
+ * seconds to see if the directory now exists), this avoids
+ * unnecessary wakeups. */
+ if (parent_type == G_FILE_TYPE_DIRECTORY)
+ priv->monitors[i] = g_file_monitor_file (file,
+ G_FILE_MONITOR_NONE,
+ NULL, NULL);
g_object_unref (file);
if (priv->monitors[i])
@@ -227,7 +242,8 @@ system_timezone_finalize (GObject *obj)
}
for (i = 0; i < CHECK_NB; i++) {
- g_object_unref (priv->monitors[i]);
+ if (priv->monitors[i])
+ g_object_unref (priv->monitors[i]);
priv->monitors[i] = NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]