thread: Add name to threads
So far this is used to assign names to relevant sources, but will used to name the kernel threads, when they are introduced. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
This commit is contained in:
parent
251722ec4e
commit
915bceb5a0
@ -435,6 +435,7 @@ meta_kms_new (MetaBackend *backend,
|
||||
kms = g_initable_new (META_TYPE_KMS,
|
||||
NULL, error,
|
||||
"backend", backend,
|
||||
"name", "KMS thread",
|
||||
NULL);
|
||||
kms->flags = flags;
|
||||
|
||||
|
@ -176,9 +176,13 @@ meta_thread_impl_constructed (GObject *object)
|
||||
MetaThreadImplPrivate *priv =
|
||||
meta_thread_impl_get_instance_private (thread_impl);
|
||||
GSource *source;
|
||||
g_autofree char *source_name = NULL;
|
||||
MetaThreadImplSource *impl_source;
|
||||
|
||||
source = g_source_new (&impl_source_funcs, sizeof (MetaThreadImplSource));
|
||||
source_name = g_strdup_printf ("MetaThreadImpl '%s' task source",
|
||||
meta_thread_get_name (priv->thread));
|
||||
g_source_set_name (source, source_name);
|
||||
impl_source = (MetaThreadImplSource *) source;
|
||||
impl_source->thread_impl = thread_impl;
|
||||
g_source_attach (source, priv->thread_context);
|
||||
@ -323,13 +327,16 @@ meta_thread_impl_add_source (MetaThreadImpl *thread_impl,
|
||||
MetaThreadImplPrivate *priv =
|
||||
meta_thread_impl_get_instance_private (thread_impl);
|
||||
GSource *source;
|
||||
g_autofree char *source_name = NULL;
|
||||
MetaThreadImplIdleSource *impl_idle_source;
|
||||
|
||||
meta_assert_in_thread_impl (priv->thread);
|
||||
|
||||
source = g_source_new (&impl_idle_source_funcs,
|
||||
sizeof (MetaThreadImplIdleSource));
|
||||
g_source_set_name (source, "[mutter] MetaThreadImpl idle source");
|
||||
source_name = g_strdup_printf ("[mutter] MetaThreadImpl '%s' idle source",
|
||||
meta_thread_get_name (priv->thread));
|
||||
g_source_set_name (source, source_name);
|
||||
impl_idle_source = (MetaThreadImplIdleSource *) source;
|
||||
impl_idle_source->thread_impl = thread_impl;
|
||||
|
||||
@ -415,13 +422,16 @@ meta_thread_impl_register_fd (MetaThreadImpl *thread_impl,
|
||||
MetaThreadImplPrivate *priv =
|
||||
meta_thread_impl_get_instance_private (thread_impl);
|
||||
GSource *source;
|
||||
g_autofree char *source_name = NULL;
|
||||
MetaThreadImplFdSource *impl_fd_source;
|
||||
|
||||
meta_assert_in_thread_impl (priv->thread);
|
||||
|
||||
source = g_source_new (&impl_fd_source_funcs,
|
||||
sizeof (MetaThreadImplFdSource));
|
||||
g_source_set_name (source, "[mutter] MetaThreadImpl fd source");
|
||||
source_name = g_strdup_printf ("[mutter] MetaThreadImpl '%s' fd source",
|
||||
meta_thread_get_name (priv->thread));
|
||||
g_source_set_name (source, source_name);
|
||||
impl_fd_source = (MetaThreadImplFdSource *) source;
|
||||
impl_fd_source->dispatch = dispatch;
|
||||
impl_fd_source->user_data = user_data;
|
||||
|
@ -30,6 +30,7 @@ enum
|
||||
PROP_0,
|
||||
|
||||
PROP_BACKEND,
|
||||
PROP_NAME,
|
||||
|
||||
N_PROPS
|
||||
};
|
||||
@ -46,6 +47,7 @@ typedef struct _MetaThreadCallbackData
|
||||
typedef struct _MetaThreadPrivate
|
||||
{
|
||||
MetaBackend *backend;
|
||||
char *name;
|
||||
|
||||
GMainContext *main_context;
|
||||
|
||||
@ -92,6 +94,9 @@ meta_thread_get_property (GObject *object,
|
||||
case PROP_BACKEND:
|
||||
g_value_set_object (value, priv->backend);
|
||||
break;
|
||||
case PROP_NAME:
|
||||
g_value_set_string (value, priv->name);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@ -112,6 +117,9 @@ meta_thread_set_property (GObject *object,
|
||||
case PROP_BACKEND:
|
||||
priv->backend = g_value_get_object (value);
|
||||
break;
|
||||
case PROP_NAME:
|
||||
priv->name = g_value_dup_string (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@ -161,6 +169,7 @@ meta_thread_finalize (GObject *object)
|
||||
g_clear_handle_id (&priv->callbacks_source_id, g_source_remove);
|
||||
|
||||
g_clear_object (&priv->impl);
|
||||
g_clear_pointer (&priv->name, g_free);
|
||||
|
||||
G_OBJECT_CLASS (meta_thread_parent_class)->finalize (object);
|
||||
}
|
||||
@ -183,6 +192,15 @@ meta_thread_class_init (MetaThreadClass *klass)
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
obj_props[PROP_NAME] =
|
||||
g_param_spec_string ("name",
|
||||
"name",
|
||||
"Name of thread",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, obj_props);
|
||||
}
|
||||
|
||||
@ -339,6 +357,14 @@ meta_thread_get_backend (MetaThread *thread)
|
||||
return priv->backend;
|
||||
}
|
||||
|
||||
const char *
|
||||
meta_thread_get_name (MetaThread *thread)
|
||||
{
|
||||
MetaThreadPrivate *priv = meta_thread_get_instance_private (thread);
|
||||
|
||||
return priv->name;
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_thread_is_in_impl_task (MetaThread *thread)
|
||||
{
|
||||
|
@ -73,6 +73,9 @@ void meta_thread_post_impl_task (MetaThread *thread,
|
||||
META_EXPORT_TEST
|
||||
MetaBackend * meta_thread_get_backend (MetaThread *thread);
|
||||
|
||||
META_EXPORT_TEST
|
||||
const char * meta_thread_get_name (MetaThread *thread);
|
||||
|
||||
META_EXPORT_TEST
|
||||
gboolean meta_thread_is_in_impl_task (MetaThread *thread);
|
||||
|
||||
|
@ -552,11 +552,13 @@ meta_test_thread_user_common (void)
|
||||
thread = g_initable_new (META_TYPE_THREAD_TEST,
|
||||
NULL, &error,
|
||||
"backend", backend,
|
||||
"name", "test user thread",
|
||||
NULL);
|
||||
g_object_add_weak_pointer (G_OBJECT (thread), (gpointer *) &thread);
|
||||
g_assert_nonnull (thread);
|
||||
g_assert_null (error);
|
||||
g_assert (meta_thread_get_backend (thread) == backend);
|
||||
g_assert_cmpstr (meta_thread_get_name (thread), ==, "test user thread");
|
||||
test_thread = thread;
|
||||
|
||||
run_thread_tests (thread);
|
||||
@ -589,6 +591,7 @@ meta_test_thread_user_late_callbacks (void)
|
||||
thread = g_initable_new (META_TYPE_THREAD_TEST,
|
||||
NULL, &error,
|
||||
"backend", backend,
|
||||
"name", "test late callback",
|
||||
NULL);
|
||||
g_object_add_weak_pointer (G_OBJECT (thread), (gpointer *) &thread);
|
||||
g_assert_nonnull (thread);
|
||||
|
Loading…
Reference in New Issue
Block a user