mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 11:20:23 +01:00
all: prefer nm wrappers to automatically attach GSource to default context
We often create the source with default priority, no destroy function and attach it to the default context (g_main_context_default()). For that case, we have wrapper functions like nm_g_timeout_add_source() and nm_g_idle_add_source(). Use those. There should be no change in behavior.
This commit is contained in:
parent
9b030a3988
commit
216c46c881
9 changed files with 25 additions and 55 deletions
|
|
@ -748,12 +748,8 @@ _ipv4ll_set_timed_out_update(NML3IPv4LL *self, TimedOutState new_state)
|
|||
if (self->timed_out_expiry_msec == 0 || self->timed_out_expiry_msec < expiry_msec) {
|
||||
self->timed_out_expiry_msec = expiry_msec;
|
||||
nm_clear_g_source_inst(&self->timed_out_source);
|
||||
self->timed_out_source = nm_g_timeout_source_new(timeout_msec,
|
||||
G_PRIORITY_DEFAULT,
|
||||
_ipv4ll_set_timed_out_timeout_cb,
|
||||
self,
|
||||
NULL);
|
||||
g_source_attach(self->timed_out_source, NULL);
|
||||
self->timed_out_source =
|
||||
nm_g_timeout_add_source(timeout_msec, _ipv4ll_set_timed_out_timeout_cb, self);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -921,11 +917,8 @@ _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_IDLE,
|
||||
_ipv4ll_state_change_on_idle_cb,
|
||||
self,
|
||||
NULL);
|
||||
g_source_attach(self->state_change_on_idle_source, NULL);
|
||||
self->state_change_on_idle_source =
|
||||
nm_g_idle_add_source(_ipv4ll_state_change_on_idle_cb, self);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1743,9 +1743,7 @@ again:
|
|||
|
||||
n_acd_get_fd(self->priv.p->nacd, &fd);
|
||||
|
||||
self->priv.p->nacd_source =
|
||||
nm_g_unix_fd_source_new(fd, G_IO_IN, G_PRIORITY_DEFAULT, _l3_acd_nacd_event, self, NULL);
|
||||
nm_g_source_attach(self->priv.p->nacd_source, NULL);
|
||||
self->priv.p->nacd_source = nm_g_unix_fd_add_source(fd, G_IO_IN, _l3_acd_nacd_event, self);
|
||||
|
||||
NM_SET_OUT(out_acd_not_supported, FALSE);
|
||||
return self->priv.p->nacd;
|
||||
|
|
|
|||
|
|
@ -114,13 +114,10 @@ st_sd_init(NMSessionMonitor *monitor)
|
|||
return;
|
||||
}
|
||||
|
||||
monitor->sd.watch = nm_g_unix_fd_source_new(sd_login_monitor_get_fd(monitor->sd.monitor),
|
||||
monitor->sd.watch = nm_g_unix_fd_add_source(sd_login_monitor_get_fd(monitor->sd.monitor),
|
||||
G_IO_IN,
|
||||
G_PRIORITY_DEFAULT,
|
||||
st_sd_changed,
|
||||
monitor,
|
||||
NULL);
|
||||
g_source_attach(monitor->sd.watch, NULL);
|
||||
monitor);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -2778,13 +2778,7 @@ nmtstp_acd_defender_new(int ifindex, in_addr_t ip_addr, const NMEtherAddr *mac_a
|
|||
n_acd_get_fd(defender->nacd, &fd);
|
||||
g_assert_cmpint(fd, >=, 0);
|
||||
|
||||
defender->source = nm_g_source_attach(nm_g_unix_fd_source_new(fd,
|
||||
G_IO_IN,
|
||||
G_PRIORITY_DEFAULT,
|
||||
_l3_acd_nacd_event,
|
||||
defender,
|
||||
NULL),
|
||||
NULL);
|
||||
defender->source = nm_g_unix_fd_add_source(fd, G_IO_IN, _l3_acd_nacd_event, defender);
|
||||
|
||||
return defender;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9759,13 +9759,10 @@ constructed(GObject *_object)
|
|||
fd);
|
||||
|
||||
priv->event_source =
|
||||
nm_g_unix_fd_source_new(fd,
|
||||
nm_g_unix_fd_add_source(fd,
|
||||
G_IO_IN | G_IO_NVAL | G_IO_PRI | G_IO_ERR | G_IO_HUP,
|
||||
G_PRIORITY_DEFAULT,
|
||||
event_handler,
|
||||
platform,
|
||||
NULL);
|
||||
g_source_attach(priv->event_source, NULL);
|
||||
platform);
|
||||
|
||||
/* complete construction of the GObject instance before populating the cache. */
|
||||
G_OBJECT_CLASS(nm_linux_platform_parent_class)->constructed(_object);
|
||||
|
|
|
|||
|
|
@ -625,12 +625,7 @@ main(int argc, const char *const *argv)
|
|||
|
||||
sigterm_cancellable = g_cancellable_new();
|
||||
|
||||
sigterm_source = nm_g_source_attach(nm_g_unix_signal_source_new(SIGTERM,
|
||||
G_PRIORITY_DEFAULT,
|
||||
sigterm_handler,
|
||||
sigterm_cancellable,
|
||||
NULL),
|
||||
NULL);
|
||||
sigterm_source = nm_g_unix_signal_add_source(SIGTERM, sigterm_handler, sigterm_cancellable);
|
||||
|
||||
provider = _provider_detect(sigterm_cancellable);
|
||||
if (!provider)
|
||||
|
|
|
|||
|
|
@ -680,14 +680,13 @@ _mhandle_socketfunction_cb(CURL *e_handle,
|
|||
condition = 0;
|
||||
|
||||
if (condition) {
|
||||
source_socket = nm_g_unix_fd_source_new(fd,
|
||||
condition,
|
||||
G_PRIORITY_DEFAULT,
|
||||
_mhandle_socket_cb,
|
||||
self,
|
||||
NULL);
|
||||
g_source_attach(source_socket, priv->context);
|
||||
|
||||
source_socket = _source_attach(self,
|
||||
nm_g_unix_fd_source_new(fd,
|
||||
condition,
|
||||
G_PRIORITY_DEFAULT,
|
||||
_mhandle_socket_cb,
|
||||
self,
|
||||
NULL));
|
||||
g_hash_table_insert(priv->source_sockets_hashtable, GINT_TO_POINTER(fd), source_socket);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -889,13 +889,7 @@ nmc_readline_helper(const NmcConfig *nmc_config, const char *prompt)
|
|||
|
||||
nmc_set_in_readline(TRUE);
|
||||
|
||||
io_source = nm_g_unix_fd_source_new(STDIN_FILENO,
|
||||
G_IO_IN,
|
||||
G_PRIORITY_DEFAULT,
|
||||
stdin_ready_cb,
|
||||
NULL,
|
||||
NULL);
|
||||
g_source_attach(io_source, NULL);
|
||||
io_source = nm_g_unix_fd_add_source(STDIN_FILENO, G_IO_IN, stdin_ready_cb, NULL);
|
||||
|
||||
read_again:
|
||||
rl_string = NULL;
|
||||
|
|
|
|||
|
|
@ -8280,9 +8280,12 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty
|
|||
connection_changed = FALSE;
|
||||
}
|
||||
|
||||
source = g_timeout_source_new(10 * NM_UTILS_MSEC_PER_SEC);
|
||||
g_source_set_callback(source, editor_save_timeout, &timeout, NULL);
|
||||
g_source_attach(source, g_main_loop_get_context(loop));
|
||||
source = nm_g_source_attach(nm_g_timeout_source_new(10 * NM_UTILS_MSEC_PER_SEC,
|
||||
G_PRIORITY_DEFAULT,
|
||||
editor_save_timeout,
|
||||
&timeout,
|
||||
NULL),
|
||||
g_main_loop_get_context(loop));
|
||||
|
||||
while (!nmc_editor_cb_called && !timeout)
|
||||
g_main_context_iteration(NULL, TRUE);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue