From 9b030a398895e554e0848f562dcd0fc307263288 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 8 Mar 2022 14:29:51 +0100 Subject: [PATCH] all: change scheduling priority for idle actions to G_PRIORITY_DEFAULT_IDLE g_idle_add() uses G_PRIORITY_DEFAULT_IDLE priority. Most of the time we don't care much about the priority. But at the places that this patch changes, I think that using G_PRIORITY_DEFAULT_IDLE (and following g_idle_add()) is more correct. The reason for this is not very strong, except that it's probably the better choice. And the old choice was made because I didn't realize that g_idle_add() uses another default priority. Hence, the old choice was not for good reasons either. --- src/core/nm-l3-ipv4ll.c | 6 ++++-- src/libnm-client-impl/nm-client.c | 5 ++++- src/libnm-glib-aux/nm-shared-utils.c | 12 +++++++++--- src/nm-cloud-setup/nm-cloud-setup-utils.c | 4 ++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/core/nm-l3-ipv4ll.c b/src/core/nm-l3-ipv4ll.c index 68cb17fb09..503039843e 100644 --- a/src/core/nm-l3-ipv4ll.c +++ b/src/core/nm-l3-ipv4ll.c @@ -921,8 +921,10 @@ _ipv4ll_state_change_on_idle(NML3IPv4LL *self) nm_assert(NM_IS_L3_IPV4LL(self)); if (!self->state_change_on_idle_source) { - self->state_change_on_idle_source = - nm_g_idle_source_new(G_PRIORITY_DEFAULT, _ipv4ll_state_change_on_idle_cb, self, NULL); + self->state_change_on_idle_source = nm_g_idle_source_new(G_PRIORITY_DEFAULT_IDLE, + _ipv4ll_state_change_on_idle_cb, + self, + NULL); g_source_attach(self->state_change_on_idle_source, NULL); } } diff --git a/src/libnm-client-impl/nm-client.c b/src/libnm-client-impl/nm-client.c index cd2aa73055..f794ff9e93 100644 --- a/src/libnm-client-impl/nm-client.c +++ b/src/libnm-client-impl/nm-client.c @@ -7349,7 +7349,10 @@ _init_start_with_bus(NMClient *self) NULL); if (id == 0) { priv->init_data->cancel_on_idle_source = - nm_g_idle_source_new(G_PRIORITY_DEFAULT, _init_start_cancel_on_idle_cb, self, NULL); + nm_g_idle_source_new(G_PRIORITY_DEFAULT_IDLE, + _init_start_cancel_on_idle_cb, + self, + NULL); g_source_attach(priv->init_data->cancel_on_idle_source, priv->main_context); return; } diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index 847e85bb67..f059741e23 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -4691,14 +4691,20 @@ _nm_utils_invoke_on_idle_start(gboolean use_timeout, } if (use_timeout) { + /* We use G_PRIORITY_DEFAULT_IDLE both for the with/without timeout + * case. The reason is not strong, but it seems right that the caller + * requests a lower priority than G_PRIORITY_DEFAULT. That is unlike + * what g_timeout_add() would do. */ source = nm_g_timeout_source_new(timeout_msec, - G_PRIORITY_DEFAULT, + G_PRIORITY_DEFAULT_IDLE, _nm_utils_invoke_on_idle_cb_idle, data, NULL); } else { - source = - nm_g_idle_source_new(G_PRIORITY_DEFAULT, _nm_utils_invoke_on_idle_cb_idle, data, NULL); + source = nm_g_idle_source_new(G_PRIORITY_DEFAULT_IDLE, + _nm_utils_invoke_on_idle_cb_idle, + data, + NULL); } /* use the current thread default context. */ diff --git a/src/nm-cloud-setup/nm-cloud-setup-utils.c b/src/nm-cloud-setup/nm-cloud-setup-utils.c index bf705549f3..e505f8bd03 100644 --- a/src/nm-cloud-setup/nm-cloud-setup-utils.c +++ b/src/nm-cloud-setup/nm-cloud-setup-utils.c @@ -146,7 +146,7 @@ nmcs_wait_for_objects_iterate_until_done(GMainContext *context, int timeout_msec nm_auto_destroy_and_unref_gsource GSource *idle_source = NULL; idle_source = - nm_g_source_attach(nm_g_idle_source_new(G_PRIORITY_DEFAULT, + nm_g_source_attach(nm_g_idle_source_new(G_PRIORITY_DEFAULT_IDLE, _wait_for_objects_iterate_until_done_idle_cb, &data, NULL), @@ -364,7 +364,7 @@ nmcs_utils_poll(int poll_timeout_ms, } poll_task_data->source_next_poll = nm_g_source_attach( - nm_g_idle_source_new(G_PRIORITY_DEFAULT, _poll_start_cb, poll_task_data, NULL), + nm_g_idle_source_new(G_PRIORITY_DEFAULT_IDLE, _poll_start_cb, poll_task_data, NULL), poll_task_data->context); if (cancellable) {