thread: Add private API to flush callbacks for main context

This will be used to flush out certain callbacks when switching thread
type.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
This commit is contained in:
Jonas Ådahl 2022-12-21 17:55:54 +01:00
parent 2617bd8e72
commit 84ff167328
2 changed files with 25 additions and 0 deletions

View File

@ -33,4 +33,7 @@ MetaThreadType meta_thread_get_thread_type (MetaThread *thread);
GThread * meta_thread_get_thread (MetaThread *thread);
void meta_thread_dispatch_callbacks (MetaThread *thread,
GMainContext *main_context);
#endif /* META_THREAD_PRIVATE_H */

View File

@ -704,6 +704,28 @@ dispatch_callbacks (MetaThread *thread,
return callback_count;
}
void
meta_thread_dispatch_callbacks (MetaThread *thread,
GMainContext *main_context)
{
MetaThreadPrivate *priv = meta_thread_get_instance_private (thread);
MetaThreadCallbackSource *callback_source;
g_autoptr (GList) pending_callbacks = NULL;
if (!main_context)
main_context = g_main_context_default ();
callback_source = g_hash_table_lookup (priv->callback_sources, main_context);
g_assert (callback_source->main_context == main_context);
g_mutex_lock (&priv->callbacks_mutex);
pending_callbacks = g_steal_pointer (&callback_source->callbacks);
g_mutex_unlock (&priv->callbacks_mutex);
dispatch_callbacks (thread, pending_callbacks);
}
void
meta_thread_flush_callbacks (MetaThread *thread)
{