From 2617bd8e727dc319609dbc6449a94094b7ab18d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 21 Dec 2022 17:24:41 +0100 Subject: [PATCH] thread/impl: Add 'reset' signal This signal is emitted before terminating the thread, but also when resetting the thread type. This is to allow thread implementations to make sure they have no stale pending callbacks to any old main contexts. This commit "terminates" the impl thread even if there is no actual thread; this is to trigger the "reset" signal, also when switching from a user thread to a kernel thread. Part-of: --- src/backends/native/meta-thread-impl.c | 18 ++++++++++++++++++ src/backends/native/meta-thread.c | 1 + 2 files changed, 19 insertions(+) diff --git a/src/backends/native/meta-thread-impl.c b/src/backends/native/meta-thread-impl.c index 763233739..cae291393 100644 --- a/src/backends/native/meta-thread-impl.c +++ b/src/backends/native/meta-thread-impl.c @@ -27,6 +27,15 @@ #define META_THREAD_IMPL_TERMINATE ((gpointer) 1) +enum +{ + RESET, + + N_SIGNALS +}; + +static guint signals[N_SIGNALS]; + enum { PROP_0, @@ -252,6 +261,14 @@ meta_thread_impl_class_init (MetaThreadImplClass *klass) G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, N_PROPS, obj_props); + + signals[RESET] = + g_signal_new ("reset", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, NULL, + G_TYPE_NONE, 0); } static void @@ -517,6 +534,7 @@ meta_thread_impl_dispatch (MetaThreadImpl *thread_impl) if (task == META_THREAD_IMPL_TERMINATE) { + g_signal_emit (thread_impl, signals[RESET], 0); if (priv->loop) g_main_loop_quit (priv->loop); return 0; diff --git a/src/backends/native/meta-thread.c b/src/backends/native/meta-thread.c index 5ca35b7da..d1a1f9e95 100644 --- a/src/backends/native/meta-thread.c +++ b/src/backends/native/meta-thread.c @@ -534,6 +534,7 @@ finalize_thread_user (MetaThread *thread) { MetaThreadPrivate *priv = meta_thread_get_instance_private (thread); + meta_thread_impl_terminate (priv->impl); while (meta_thread_impl_dispatch (priv->impl) > 0); unwrap_main_context (thread, meta_thread_impl_get_main_context (priv->impl)); }