[gnome-shell] cleanup: Use g_clear_handle_id() for g_source_remove()
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] cleanup: Use g_clear_handle_id() for g_source_remove()
- Date: Fri, 22 Nov 2019 01:31:28 +0000 (UTC)
commit c48330a9861dcb62f962539e83b7479642e06698
Author: Robert Mader <robert mader posteo de>
Date: Fri Nov 22 01:42:14 2019 +0100
cleanup: Use g_clear_handle_id() for g_source_remove()
It makes sure we do not forget to zero the id and lets us avoid
zero checks before. We use it for all new code, lets clean up the
existing code base.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/845
src/calendar-server/calendar-sources.c | 12 ++----------
src/calendar-server/gnome-shell-calendar-server.c | 3 +--
src/hotplug-sniffer/hotplug-sniffer.c | 6 +-----
src/hotplug-sniffer/shell-mime-sniffer.c | 6 +-----
src/shell-app-usage.c | 9 ++-------
src/shell-perf-helper.c | 3 +--
src/shell-perf-log.c | 3 +--
src/shell-recorder-src.c | 3 +--
src/shell-recorder.c | 21 ++++-----------------
src/st/st-scroll-bar.c | 9 ++-------
10 files changed, 16 insertions(+), 59 deletions(-)
---
diff --git a/src/calendar-server/calendar-sources.c b/src/calendar-server/calendar-sources.c
index 7e4c7f52e1..bdc1454219 100644
--- a/src/calendar-server/calendar-sources.c
+++ b/src/calendar-server/calendar-sources.c
@@ -242,11 +242,7 @@ calendar_sources_finalize_source_data (CalendarSources *sources,
g_hash_table_destroy (source_data->clients);
source_data->clients = NULL;
- if (source_data->timeout_id != 0)
- {
- g_source_remove (source_data->timeout_id);
- source_data->timeout_id = 0;
- }
+ g_clear_handle_id (&source_data->timeout_id, g_source_remove);
source_data->loaded = FALSE;
}
@@ -374,11 +370,7 @@ backend_died_cb (EClient *client, CalendarSourceData *source_data)
g_warning ("The calendar backend for '%s' has crashed.", display_name);
g_hash_table_remove (source_data->clients, source);
- if (source_data->timeout_id != 0)
- {
- g_source_remove (source_data->timeout_id);
- source_data->timeout_id = 0;
- }
+ g_clear_handle_id (&source_data->timeout_id, g_source_remove);
source_data->timeout_id = g_timeout_add_seconds (2, backend_restart,
source_data);
diff --git a/src/calendar-server/gnome-shell-calendar-server.c
b/src/calendar-server/gnome-shell-calendar-server.c
index d04f0019cb..25cb694db3 100644
--- a/src/calendar-server/gnome-shell-calendar-server.c
+++ b/src/calendar-server/gnome-shell-calendar-server.c
@@ -792,8 +792,7 @@ app_free (App *app)
g_clear_signal_handler (&app->sources_signal_id, app->sources);
g_object_unref (app->sources);
- if (app->changed_timeout_id != 0)
- g_source_remove (app->changed_timeout_id);
+ g_clear_handle_id (&app->changed_timeout_id, g_source_remove);
g_free (app);
}
diff --git a/src/hotplug-sniffer/hotplug-sniffer.c b/src/hotplug-sniffer/hotplug-sniffer.c
index b8d7fa0ea8..fd087fd738 100644
--- a/src/hotplug-sniffer/hotplug-sniffer.c
+++ b/src/hotplug-sniffer/hotplug-sniffer.c
@@ -60,11 +60,7 @@ ensure_autoquit_off (void)
if (g_getenv ("HOTPLUG_SNIFFER_PERSIST") != NULL)
return;
- if (autoquit_id != 0)
- {
- g_source_remove (autoquit_id);
- autoquit_id = 0;
- }
+ g_clear_handle_id (&autoquit_id, g_source_remove);
}
static void
diff --git a/src/hotplug-sniffer/shell-mime-sniffer.c b/src/hotplug-sniffer/shell-mime-sniffer.c
index cf53579a09..6c56ecbaf5 100644
--- a/src/hotplug-sniffer/shell-mime-sniffer.c
+++ b/src/hotplug-sniffer/shell-mime-sniffer.c
@@ -483,11 +483,7 @@ shell_mime_sniffer_dispose (GObject *object)
g_clear_object (&self->priv->cancellable);
g_clear_object (&self->priv->task);
- if (self->priv->watchdog_id != 0)
- {
- g_source_remove (self->priv->watchdog_id);
- self->priv->watchdog_id = 0;
- }
+ g_clear_handle_id (&self->priv->watchdog_id, g_source_remove);
G_OBJECT_CLASS (shell_mime_sniffer_parent_class)->dispose (object);
}
diff --git a/src/shell-app-usage.c b/src/shell-app-usage.c
index b8c3e75674..0dfb209938 100644
--- a/src/shell-app-usage.c
+++ b/src/shell-app-usage.c
@@ -328,8 +328,7 @@ shell_app_usage_finalize (GObject *object)
{
ShellAppUsage *self = SHELL_APP_USAGE (object);
- if (self->save_id > 0)
- g_source_remove (self->save_id);
+ g_clear_handle_id (&self->save_id, g_source_remove);
g_object_unref (self->privacy_settings);
@@ -743,11 +742,7 @@ update_enable_monitoring (ShellAppUsage *self)
if (self->watched_app)
g_object_unref (self->watched_app);
self->watched_app = NULL;
- if (self->save_id)
- {
- g_source_remove (self->save_id);
- self->save_id = 0;
- }
+ g_clear_handle_id (&self->save_id, g_source_remove);
}
self->enable_monitoring = enable;
diff --git a/src/shell-perf-helper.c b/src/shell-perf-helper.c
index e5eab208ba..f115dcbdc8 100644
--- a/src/shell-perf-helper.c
+++ b/src/shell-perf-helper.c
@@ -84,8 +84,7 @@ on_timeout (gpointer data)
static void
establish_timeout (void)
{
- if (timeout_id != 0)
- g_source_remove (timeout_id);
+ g_clear_handle_id (&timeout_id, g_source_remove);
timeout_id = g_timeout_add (opt_idle_timeout * 1000, on_timeout, NULL);
g_source_set_name_by_id (timeout_id, "[gnome-shell] on_timeout");
diff --git a/src/shell-perf-log.c b/src/shell-perf-log.c
index cca3dc5b19..e6fbb36153 100644
--- a/src/shell-perf-log.c
+++ b/src/shell-perf-log.c
@@ -218,8 +218,7 @@ shell_perf_log_set_enabled (ShellPerfLog *perf_log,
}
else
{
- g_source_remove (perf_log->statistics_timeout_id);
- perf_log->statistics_timeout_id = 0;
+ g_clear_handle_id (&perf_log->statistics_timeout_id, g_source_remove);
}
}
}
diff --git a/src/shell-recorder-src.c b/src/shell-recorder-src.c
index d1a1640385..617e3c0c40 100644
--- a/src/shell-recorder-src.c
+++ b/src/shell-recorder-src.c
@@ -241,8 +241,7 @@ shell_recorder_src_finalize (GObject *object)
{
ShellRecorderSrc *src = SHELL_RECORDER_SRC (object);
- if (src->memory_used_update_idle)
- g_source_remove (src->memory_used_update_idle);
+ g_clear_handle_id (&src->memory_used_update_idle, g_source_remove);
shell_recorder_src_set_caps (src, NULL);
g_queue_free_full (src->queue, (GDestroyNotify) gst_buffer_unref);
diff --git a/src/shell-recorder.c b/src/shell-recorder.c
index cfafbaa0af..43600ebbd0 100644
--- a/src/shell-recorder.c
+++ b/src/shell-recorder.c
@@ -220,8 +220,7 @@ shell_recorder_finalize (GObject *object)
{
ShellRecorder *recorder = SHELL_RECORDER (object);
- if (recorder->update_memory_used_timeout)
- g_source_remove (recorder->update_memory_used_timeout);
+ g_clear_handle_id (&recorder->update_memory_used_timeout, g_source_remove);
if (recorder->cursor_image)
cairo_surface_destroy (recorder->cursor_image);
@@ -298,11 +297,7 @@ recorder_add_redraw_timeout (ShellRecorder *recorder)
static void
recorder_remove_redraw_timeout (ShellRecorder *recorder)
{
- if (recorder->redraw_timeout != 0)
- {
- g_source_remove (recorder->redraw_timeout);
- recorder->redraw_timeout = 0;
- }
+ g_clear_handle_id (&recorder->redraw_timeout, g_source_remove);
}
static void
@@ -608,11 +603,7 @@ recorder_add_update_pointer_timeout (ShellRecorder *recorder)
static void
recorder_remove_update_pointer_timeout (ShellRecorder *recorder)
{
- if (recorder->update_pointer_timeout)
- {
- g_source_remove (recorder->update_pointer_timeout);
- recorder->update_pointer_timeout = 0;
- }
+ g_clear_handle_id (&recorder->update_pointer_timeout, g_source_remove);
}
static void
@@ -648,11 +639,7 @@ recorder_disconnect_stage_callbacks (ShellRecorder *recorder)
* us the events is close to free in any case.
*/
- if (recorder->redraw_idle)
- {
- g_source_remove (recorder->redraw_idle);
- recorder->redraw_idle = 0;
- }
+ g_clear_handle_id (&recorder->redraw_idle, g_source_remove);
}
static void
diff --git a/src/st/st-scroll-bar.c b/src/st/st-scroll-bar.c
index 3f118b0991..c4551b5e90 100644
--- a/src/st/st-scroll-bar.c
+++ b/src/st/st-scroll-bar.c
@@ -818,11 +818,7 @@ trough_button_release_event_cb (ClutterActor *actor,
if (event->button != 1)
return FALSE;
- if (priv->paging_source_id)
- {
- g_source_remove (priv->paging_source_id);
- priv->paging_source_id = 0;
- }
+ g_clear_handle_id (&priv->paging_source_id, g_source_remove);
return TRUE;
}
@@ -836,8 +832,7 @@ trough_leave_event_cb (ClutterActor *actor,
if (priv->paging_source_id)
{
- g_source_remove (priv->paging_source_id);
- priv->paging_source_id = 0;
+ g_clear_handle_id (&priv->paging_source_id, g_source_remove);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]