From db6bf9d14e279f99e6fbcd99b5ee9379d0685e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 19 Jan 2021 22:14:01 +0100 Subject: [PATCH] backend: Tear down in dispose() instead of finalize() This means backend implementations can have more control of the order of how things are destroyed. To be precise, this will, in the next commit, allow us to destroy the logind integration after the clutter backend thus the libinput owning seat, that uses the logind integration to release input devices. Part-of: --- src/backends/meta-backend.c | 26 +++++++++++++++++------ src/backends/native/meta-backend-native.c | 13 +++++++----- src/backends/x11/meta-backend-x11.c | 6 +++--- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index aca0d6fc9..14f15d66a 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -191,12 +191,16 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (MetaBackend, meta_backend, G_TYPE_OBJECT, initable_iface_init)); static void -meta_backend_finalize (GObject *object) +meta_backend_dispose (GObject *object) { MetaBackend *backend = META_BACKEND (object); MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); - g_list_free_full (priv->gpus, g_object_unref); + if (priv->gpus) + { + g_list_free_full (priv->gpus, g_object_unref); + priv->gpus = NULL; + } g_clear_object (&priv->current_device); g_clear_object (&priv->monitor_manager); @@ -213,9 +217,17 @@ meta_backend_finalize (GObject *object) #endif if (priv->sleep_signal_id) - g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id); + { + g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id); + priv->sleep_signal_id = 0; + } + if (priv->upower_watch_id) - g_bus_unwatch_name (priv->upower_watch_id); + { + g_bus_unwatch_name (priv->upower_watch_id); + priv->upower_watch_id = 0; + } + g_cancellable_cancel (priv->cancellable); g_clear_object (&priv->cancellable); g_clear_object (&priv->system_bus); @@ -223,7 +235,7 @@ meta_backend_finalize (GObject *object) g_clear_handle_id (&priv->device_update_idle_id, g_source_remove); - g_hash_table_destroy (priv->device_monitors); + g_clear_pointer (&priv->device_monitors, g_hash_table_destroy); g_clear_object (&priv->settings); @@ -233,7 +245,7 @@ meta_backend_finalize (GObject *object) g_clear_object (&priv->clutter_backend); - G_OBJECT_CLASS (meta_backend_parent_class)->finalize (object); + G_OBJECT_CLASS (meta_backend_parent_class)->dispose (object); } static void @@ -805,7 +817,7 @@ meta_backend_class_init (MetaBackendClass *klass) const gchar *mutter_stage_views; GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = meta_backend_finalize; + object_class->dispose = meta_backend_dispose; object_class->constructed = meta_backend_constructed; klass->post_init = meta_backend_real_post_init; diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index fee6f7601..473508305 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -89,18 +89,21 @@ static void disconnect_udev_device_added_handler (MetaBackendNative *native); static void -meta_backend_native_finalize (GObject *object) +meta_backend_native_dispose (GObject *object) { MetaBackendNative *native = META_BACKEND_NATIVE (object); if (native->udev_device_added_handler_id) - disconnect_udev_device_added_handler (native); + { + disconnect_udev_device_added_handler (native); + native->udev_device_added_handler_id = 0; + } g_clear_object (&native->kms); g_clear_object (&native->udev); - meta_launcher_free (native->launcher); + g_clear_pointer (&native->launcher, meta_launcher_free); - G_OBJECT_CLASS (meta_backend_native_parent_class)->finalize (object); + G_OBJECT_CLASS (meta_backend_native_parent_class)->dispose (object); } static ClutterBackend * @@ -521,7 +524,7 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass) MetaBackendClass *backend_class = META_BACKEND_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = meta_backend_native_finalize; + object_class->dispose = meta_backend_native_dispose; backend_class->create_clutter_backend = meta_backend_native_create_clutter_backend; diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c index f79b0d6d4..722d7b3d9 100644 --- a/src/backends/x11/meta-backend-x11.c +++ b/src/backends/x11/meta-backend-x11.c @@ -848,7 +848,7 @@ initable_iface_init (GInitableIface *initable_iface) } static void -meta_backend_x11_finalize (GObject *object) +meta_backend_x11_dispose (GObject *object) { MetaBackend *backend = META_BACKEND (object); MetaBackendX11 *x11 = META_BACKEND_X11 (object); @@ -871,7 +871,7 @@ meta_backend_x11_finalize (GObject *object) priv->user_active_alarm = None; } - G_OBJECT_CLASS (meta_backend_x11_parent_class)->finalize (object); + G_OBJECT_CLASS (meta_backend_x11_parent_class)->dispose (object); } static void @@ -880,7 +880,7 @@ meta_backend_x11_class_init (MetaBackendX11Class *klass) MetaBackendClass *backend_class = META_BACKEND_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = meta_backend_x11_finalize; + object_class->dispose = meta_backend_x11_dispose; backend_class->create_clutter_backend = meta_backend_x11_create_clutter_backend; backend_class->post_init = meta_backend_x11_post_init; backend_class->grab_device = meta_backend_x11_grab_device;