kms: Prepare shutdown on 'prepare-shutdown' signal

Doing it in dispose means the backend is actively tearing down itself,
meaning various components might or might not be there, depending on how
the tearing down is implemented. Make things a bit more robust by doing
any work that might rely on the backend being there before shutdown is
done in response to the 'prepare-shutdown' signal being emitted by the
backend.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2853>
This commit is contained in:
Jonas Ådahl 2022-06-04 21:39:10 +02:00 committed by Marge Bot
parent 5f34d1eae2
commit c6b454d00f
3 changed files with 27 additions and 21 deletions

View File

@ -113,9 +113,6 @@ meta_backend_native_dispose (GObject *object)
{
MetaBackendNative *native = META_BACKEND_NATIVE (object);
if (native->kms)
meta_kms_prepare_shutdown (native->kms);
G_OBJECT_CLASS (meta_backend_native_parent_class)->dispose (object);
g_clear_pointer (&native->startup_render_devices, g_hash_table_unref);

View File

@ -708,6 +708,23 @@ meta_kms_create_device (MetaKms *kms,
return device;
}
static gpointer
prepare_shutdown_in_impl (MetaKmsImpl *impl,
gpointer user_data,
GError **error)
{
meta_kms_impl_prepare_shutdown (impl);
return GINT_TO_POINTER (TRUE);
}
static void
on_prepare_shutdown (MetaBackend *backend,
MetaKms *kms)
{
meta_kms_run_impl_task_sync (kms, prepare_shutdown_in_impl, NULL, NULL);
flush_callbacks (kms);
}
MetaKms *
meta_kms_new (MetaBackend *backend,
MetaKmsFlags flags,
@ -737,25 +754,13 @@ meta_kms_new (MetaBackend *backend,
g_signal_connect (udev, "device-removed",
G_CALLBACK (on_udev_device_removed), kms);
g_signal_connect (backend, "prepare-shutdown",
G_CALLBACK (on_prepare_shutdown),
kms);
return kms;
}
static gpointer
prepare_shutdown_in_impl (MetaKmsImpl *impl,
gpointer user_data,
GError **error)
{
meta_kms_impl_prepare_shutdown (impl);
return GINT_TO_POINTER (TRUE);
}
void
meta_kms_prepare_shutdown (MetaKms *kms)
{
meta_kms_run_impl_task_sync (kms, prepare_shutdown_in_impl, NULL, NULL);
flush_callbacks (kms);
}
static void
meta_kms_finalize (GObject *object)
{
@ -778,6 +783,11 @@ meta_kms_finalize (GObject *object)
G_OBJECT_CLASS (meta_kms_parent_class)->finalize (object);
}
static void
meta_kms_constructed (GObject *object)
{
}
static void
meta_kms_init (MetaKms *kms)
{
@ -789,6 +799,7 @@ meta_kms_class_init (MetaKmsClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = meta_kms_finalize;
object_class->constructed = meta_kms_constructed;
signals[RESOURCES_CHANGED] =
g_signal_new ("resources-changed",

View File

@ -66,8 +66,6 @@ MetaKmsDevice * meta_kms_create_device (MetaKms *kms,
MetaKmsDeviceFlag flags,
GError **error);
void meta_kms_prepare_shutdown (MetaKms *kms);
MetaKms * meta_kms_new (MetaBackend *backend,
MetaKmsFlags flags,
GError **error);