summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Neumann <sven@gimp.org>2008-03-03 17:45:08 -0500
committerDavid Zeuthen <davidz@redhat.com>2008-03-03 17:45:08 -0500
commit0c9383d363c6dd29da64ed4383ab9819f7f1fc99 (patch)
tree4c7f69477316a9b002c4e112736ad7463f8de176
parent4caf585c66f5490a40f458015eaac8af1c277fe8 (diff)
use g_timeout_add_seconds() where appropriate if glib 2.14 is available
As you probably know already, glib 2.14 introduced variants of the g_timeout_add() functions that operate at whole second granularity. This allows timers to be grouped, which results in a more power and CPU efficient behavior. Attached is a patch that adds a configure check for GLib 2.14 and changes some code (notably in the Linux specific parts) to use the new functions when possible.
-rw-r--r--configure.in9
-rw-r--r--hald/hald.c6
-rw-r--r--hald/hald_dbus.c5
-rw-r--r--hald/linux/acpi.c24
-rw-r--r--hald/linux/addons/addon-storage.c5
-rw-r--r--hald/linux/addons/addon-usb-csr.c4
-rw-r--r--hald/linux/apm.c10
-rw-r--r--hald/linux/blockdev.c4
-rw-r--r--hald/linux/device.c15
-rw-r--r--hald/linux/pmu.c10
10 files changed, 77 insertions, 15 deletions
diff --git a/configure.in b/configure.in
index 44bffb81..8424170e 100644
--- a/configure.in
+++ b/configure.in
@@ -622,6 +622,15 @@ PKG_CHECK_MODULES(GLIB, [$glib_module])
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
+AC_MSG_CHECKING([if GLib is version 2.14.0 or newer])
+if $PKG_CONFIG --atleast-version=2.14.0 glib-2.0; then
+ have_glib_2_14=yes
+ AC_DEFINE(HAVE_GLIB_2_14, 1, [Define to 1 if GLib is version 2.14 or newer])
+else
+ have_glib_2_14=no
+fi
+AC_MSG_RESULT($have_glib_2_14)
+
# volume_id
case "$host" in
*-*-solaris*)
diff --git a/hald/hald.c b/hald/hald.c
index 4cec63c0..8a160d51 100644
--- a/hald/hald.c
+++ b/hald/hald.c
@@ -477,9 +477,15 @@ _polkit_config_changed_cb (PolKitContext *pk_context, gpointer user_data)
g_source_remove (_polkit_cooloff_timer);
HAL_INFO (("restarting cool-off timer"));
}
+#ifdef HAVE_GLIB_2_14
+ _polkit_cooloff_timer = g_timeout_add_seconds (1,
+ _polkit_config_really_changed,
+ NULL);
+#else
_polkit_cooloff_timer = g_timeout_add (1000, /* one second... */
_polkit_config_really_changed,
NULL);
+#endif
}
#endif /* HAVE_POLKIT */
diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index 58b83899..ab87cefb 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -5167,8 +5167,11 @@ hald_dbus_filter_function (DBusConnection * connection,
dbus_connection_unref (dbus_connection);
dbus_connection = NULL;
+#ifdef HAVE_GLIB_2_14
+ g_timeout_add_seconds (3, reinit_dbus, NULL);
+#else
g_timeout_add (3000, reinit_dbus, NULL);
-
+#endif
} else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameAcquired")){
/* we don't need to do anything atm with this signal ... */
return DBUS_HANDLER_RESULT_HANDLED;
diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c
index e8bda630..d8d526ce 100644
--- a/hald/linux/acpi.c
+++ b/hald/linux/acpi.c
@@ -54,7 +54,7 @@ enum {
ACPI_TYPE_BUTTON
};
-#define ACPI_POLL_INTERVAL 30000
+#define ACPI_POLL_INTERVAL 30 /* in seconds */
typedef struct ACPIDevHandler_s
{
@@ -933,13 +933,25 @@ acpi_synthesize_hotplug_events (void)
acpi_synthesize_sonypi_display ();
/* setup timer for things that we need to poll */
- g_timeout_add (ACPI_POLL_INTERVAL,
+#ifdef HAVE_GLIB_2_14
+ g_timeout_add_seconds (ACPI_POLL_INTERVAL,
+ acpi_poll,
+ NULL);
+#else
+ g_timeout_add (1000 * ACPI_POLL_INTERVAL,
acpi_poll,
NULL);
- /* setup timer for things that we need only to poll infrequently*/
- g_timeout_add ((ACPI_POLL_INTERVAL*120),
- battery_poll_infrequently,
- NULL);
+#endif
+
+ /* setup timer for things that we need only to poll infrequently */
+
+ /* don't use g_timeout_add_seconds() here as the related code path
+ * is possibly CPU and time eating and we don't want have any
+ * other timeout synced with this one
+ */
+ g_timeout_add (1000 * ACPI_POLL_INTERVAL * 120,
+ battery_poll_infrequently,
+ NULL);
return TRUE;
}
diff --git a/hald/linux/addons/addon-storage.c b/hald/linux/addons/addon-storage.c
index abf8eaf2..d88cc43c 100644
--- a/hald/linux/addons/addon-storage.c
+++ b/hald/linux/addons/addon-storage.c
@@ -333,7 +333,12 @@ update_polling_interval (void)
if (poll_timer > 0)
g_source_remove (poll_timer);
+
+#ifdef HAVE_GLIB_2_14
+ poll_timer = g_timeout_add_seconds (interval_in_seconds, poll_for_media, NULL);
+#else
poll_timer = g_timeout_add (interval_in_seconds * 1000, poll_for_media, NULL);
+#endif
update_proc_title ();
}
diff --git a/hald/linux/addons/addon-usb-csr.c b/hald/linux/addons/addon-usb-csr.c
index b01e5ed7..4dfecdc1 100644
--- a/hald/linux/addons/addon-usb-csr.c
+++ b/hald/linux/addons/addon-usb-csr.c
@@ -330,7 +330,11 @@ main (int argc, char *argv[])
"info.product", &err));
main_loop = g_main_loop_new (NULL, FALSE);
+#ifdef HAVE_GLIB_2_14
+ g_timeout_add_seconds (TIMEOUT, check_all_batteries, NULL);
+#else
g_timeout_add (1000L * TIMEOUT, check_all_batteries, NULL);
+#endif
g_main_loop_run (main_loop);
libhal_ctx_shutdown (halctx, &err);
diff --git a/hald/linux/apm.c b/hald/linux/apm.c
index 32a831a7..57d75c7e 100644
--- a/hald/linux/apm.c
+++ b/hald/linux/apm.c
@@ -64,7 +64,7 @@ typedef struct {
int battery_time;
} APMInfo;
-#define APM_POLL_INTERVAL 2000
+#define APM_POLL_INTERVAL 2 /* in seconds */
static gboolean
apm_poll (gpointer data)
@@ -310,9 +310,15 @@ apm_synthesize_hotplug_events (void)
hotplug_event->apm.apm_type = APM_TYPE_AC_ADAPTER;
hotplug_event_enqueue (hotplug_event);
- g_timeout_add (APM_POLL_INTERVAL,
+#ifdef HAVE_GLIB_2_14
+ g_timeout_add_seconds (APM_POLL_INTERVAL,
+ apm_poll,
+ NULL);
+#else
+ g_timeout_add (1000 * APM_POLL_INTERVAL,
apm_poll,
NULL);
+#endif
out:
return ret;
diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c
index 725ed1ad..e75635de 100644
--- a/hald/linux/blockdev.c
+++ b/hald/linux/blockdev.c
@@ -734,7 +734,11 @@ refresh_md_state (HalDevice *d)
}
/* check again in two seconds */
+#ifdef HAVE_GLIB_2_14
+ g_timeout_add_seconds (2, md_check_sync_timeout, g_strdup (sysfs_path));
+#else
g_timeout_add (2000, md_check_sync_timeout, g_strdup (sysfs_path));
+#endif
}
} else
hal_device_property_set_bool (d, "storage.linux_raid.is_syncing", FALSE);
diff --git a/hald/linux/device.c b/hald/linux/device.c
index e7f4b056..e39672bd 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -74,7 +74,7 @@ gboolean _have_sysfs_power_button = FALSE;
gboolean _have_sysfs_sleep_button = FALSE;
gboolean _have_sysfs_power_supply = FALSE;
-#define POWER_SUPPLY_BATTERY_POLL_INTERVAL 30000
+#define POWER_SUPPLY_BATTERY_POLL_INTERVAL 30 /* in seconds */
/* we must use this kernel-compatible implementation */
#define BITS_PER_LONG (sizeof(long) * 8)
@@ -3408,9 +3408,16 @@ power_supply_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *
hal_device_add_capability (d, "battery");
/* setup timer for things that we need to poll */
- g_timeout_add ( POWER_SUPPLY_BATTERY_POLL_INTERVAL,
- power_supply_battery_poll,
- NULL);
+#ifdef HAVE_GLIB_2_14
+ g_timeout_add_seconds (POWER_SUPPLY_BATTERY_POLL_INTERVAL,
+ power_supply_battery_poll,
+ NULL);
+#else
+ g_timeout_add (1000 * POWER_SUPPLY_BATTERY_POLL_INTERVAL,
+ power_supply_battery_poll,
+ NULL);
+#endif
+
}
if (is_ac_adapter == TRUE) {
diff --git a/hald/linux/pmu.c b/hald/linux/pmu.c
index 451ffacd..c080ed39 100644
--- a/hald/linux/pmu.c
+++ b/hald/linux/pmu.c
@@ -68,7 +68,7 @@ typedef struct PMUDevHandler_s
#define PMU_BATT_TYPE_HOOPER 0x00000020 /* 3400/3500 */
#define PMU_BATT_TYPE_COMET 0x00000030 /* 2400 */
-#define PMU_POLL_INTERVAL 2000
+#define PMU_POLL_INTERVAL 2 /* in seconds */
#define PMUDEV "/dev/pmu"
@@ -364,9 +364,15 @@ pmu_synthesize_hotplug_events (void)
}
/* setup timer for things that we need to poll */
- g_timeout_add (PMU_POLL_INTERVAL,
+#ifdef HAVE_GLIB_2_14
+ g_timeout_add_seconds (PMU_POLL_INTERVAL,
+ pmu_poll,
+ NULL);
+#else
+ g_timeout_add (1000 * PMU_POLL_INTERVAL,
pmu_poll,
NULL);
+#endif
out:
return ret;