From 7277592255c55b87be572032579049377bb0f081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Sun, 22 Nov 2020 18:29:17 +0100 Subject: [PATCH] thread: Initialize using GInitable To later add error handling. Part-of: --- src/backends/native/meta-kms.c | 7 ++++--- src/backends/native/meta-thread.c | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/backends/native/meta-kms.c b/src/backends/native/meta-kms.c index f1dc310ac..cf94fbfc7 100644 --- a/src/backends/native/meta-kms.c +++ b/src/backends/native/meta-kms.c @@ -455,9 +455,10 @@ meta_kms_new (MetaBackend *backend, MetaUdev *udev = meta_backend_native_get_udev (backend_native); MetaKms *kms; - kms = g_object_new (META_TYPE_KMS, - "backend", backend, - NULL); + kms = g_initable_new (META_TYPE_KMS, + NULL, error, + "backend", backend, + NULL); kms->flags = flags; if (!(flags & META_KMS_FLAG_NO_MODE_SETTING)) diff --git a/src/backends/native/meta-thread.c b/src/backends/native/meta-thread.c index cd59efd72..1ba23cd1e 100644 --- a/src/backends/native/meta-thread.c +++ b/src/backends/native/meta-thread.c @@ -79,8 +79,12 @@ typedef struct _MetaThreadClassPrivate GType impl_type; } MetaThreadClassPrivate; +static void initable_iface_init (GInitableIface *initable_iface); + G_DEFINE_TYPE_WITH_CODE (MetaThread, meta_thread, G_TYPE_OBJECT, G_ADD_PRIVATE (MetaThread) + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, + initable_iface_init) g_type_add_class_private (g_define_type_id, sizeof (MetaThreadClassPrivate))) @@ -132,24 +136,32 @@ meta_thread_set_property (GObject *object, } } -static void -meta_thread_constructed (GObject *object) +static gboolean +meta_thread_initable_init (GInitable *initable, + GCancellable *cancellable, + GError **error) { - MetaThread *thread = META_THREAD (object); + MetaThread *thread = META_THREAD (initable); MetaThreadPrivate *priv = meta_thread_get_instance_private (thread); MetaThreadClass *thread_class = META_THREAD_GET_CLASS (thread); MetaThreadClassPrivate *class_priv = G_TYPE_CLASS_GET_PRIVATE (thread_class, META_TYPE_THREAD, MetaThreadClassPrivate); - G_OBJECT_CLASS (meta_thread_parent_class)->constructed (object); - priv->main_context = g_main_context_get_thread_default (); g_assert (g_type_is_a (class_priv->impl_type, META_TYPE_THREAD_IMPL)); priv->impl = g_object_new (class_priv->impl_type, "thread", thread, NULL); + + return TRUE; +} + +static void +initable_iface_init (GInitableIface *initable_iface) +{ + initable_iface->init = meta_thread_initable_init; } static void @@ -174,7 +186,6 @@ meta_thread_class_init (MetaThreadClass *klass) object_class->get_property = meta_thread_get_property; object_class->set_property = meta_thread_set_property; - object_class->constructed = meta_thread_constructed; object_class->finalize = meta_thread_finalize; obj_props[PROP_BACKEND] =