[gnome-control-center/wip/benzea/ap-list-cpu-usage] network: Move AP list population into an idle handler
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/benzea/ap-list-cpu-usage] network: Move AP list population into an idle handler
- Date: Mon, 12 Nov 2018 21:37:31 +0000 (UTC)
commit 1d969aea8a4bcddf30adc737d006f68dcaa1d2d8
Author: Benjamin Berg <bberg redhat com>
Date: Sun Nov 11 21:30:18 2018 +0100
network: Move AP list population into an idle handler
The AP list needs to be updated every time APs are added or removed.
However, such addition and removal generally happens in bulk (i.e. scan
results coming in) and doing so for every AP is wasteful.
So update the widget from an idle handler instead of updating it
immediately from the signal handler.
Fixes #152
panels/network/net-device-wifi.c | 39 +++++++++++++++++++++++++++++++++------
1 file changed, 33 insertions(+), 6 deletions(-)
---
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index 728a3cc73..c151bb3ff 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -49,7 +49,7 @@ typedef enum {
static void nm_device_wifi_refresh_ui (NetDeviceWifi *device_wifi);
static void show_wifi_list (NetDeviceWifi *device_wifi);
-static void populate_ap_list (NetDeviceWifi *device_wifi);
+static void queue_populate_ap_list (NetDeviceWifi *device_wifi);
static void show_hotspot_ui (NetDeviceWifi *device_wifi);
struct _NetDeviceWifi
@@ -64,6 +64,7 @@ struct _NetDeviceWifi
gchar *selected_connection_id;
gchar *selected_ap_id;
guint scan_id;
+ guint populate_id;
GCancellable *cancellable;
};
@@ -299,7 +300,7 @@ net_device_wifi_access_point_added (NMDeviceWifi *nm_device_wifi,
{
NetDeviceWifi *device_wifi = NET_DEVICE_WIFI (user_data);
- populate_ap_list (device_wifi);
+ queue_populate_ap_list (device_wifi);
nm_device_wifi_connect_access_points (nm_device_wifi, device_wifi);
}
@@ -310,7 +311,7 @@ net_device_wifi_access_point_removed (NMDeviceWifi *nm_device_wifi,
{
NetDeviceWifi *device_wifi = NET_DEVICE_WIFI (user_data);
- populate_ap_list (device_wifi);
+ queue_populate_ap_list (device_wifi);
}
static void
@@ -707,7 +708,7 @@ nm_device_wifi_refresh_ui (NetDeviceWifi *device_wifi)
/* update list of APs */
show_wifi_list (device_wifi);
- populate_ap_list (device_wifi);
+ queue_populate_ap_list (device_wifi);
}
static void
@@ -1519,7 +1520,7 @@ client_connection_added_cb (NMClient *client,
return;
}
- populate_ap_list (device_wifi);
+ queue_populate_ap_list (device_wifi);
show_wifi_list (device_wifi);
}
@@ -1613,6 +1614,10 @@ net_device_wifi_finalize (GObject *object)
{
NetDeviceWifi *device_wifi = NET_DEVICE_WIFI (object);
+ if (device_wifi->populate_id) {
+ g_source_remove (device_wifi->populate_id);
+ device_wifi->populate_id = 0;
+ }
if (device_wifi->cancellable) {
g_cancellable_cancel (device_wifi->cancellable);
g_clear_object (&device_wifi->cancellable);
@@ -1683,7 +1688,7 @@ really_forgotten (GObject *source_object,
}
/* remove the entry from the list */
- populate_ap_list (user_data);
+ queue_populate_ap_list (user_data);
}
static void
@@ -2216,6 +2221,28 @@ populate_ap_list (NetDeviceWifi *device_wifi)
g_ptr_array_free (aps_unique, TRUE);
}
+static gboolean
+populate_ap_list_idle_cb (NetDeviceWifi *device_wifi)
+{
+ populate_ap_list (device_wifi);
+
+ device_wifi->populate_id = 0;
+ return G_SOURCE_REMOVE;
+}
+
+static void
+queue_populate_ap_list (NetDeviceWifi *device_wifi)
+{
+ if (device_wifi->populate_id)
+ return;
+
+ /* Using the default idle could cause higher CPU usage. */
+ device_wifi->populate_id = g_idle_add_full (G_PRIORITY_DEFAULT,
+ (GSourceFunc) populate_ap_list_idle_cb,
+ device_wifi,
+ NULL);
+}
+
static void
ap_activated (GtkListBox *list, GtkListBoxRow *row, NetDeviceWifi *device_wifi)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]