thread: Make it possible to run sync tasks from any thread

When a task is posted from a non-main thread, a user thread still needs
to go via the queue and be signalled using the condition, just as if it
was a kernel thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
This commit is contained in:
Jonas Ådahl
2021-10-05 18:17:36 +02:00
parent d77b5935cd
commit 1350b5e260
2 changed files with 113 additions and 1 deletions

View File

@ -77,6 +77,8 @@ typedef struct _MetaThreadPrivate
MetaThreadType thread_type;
GThread *main_thread;
struct {
GThread *thread;
GMutex init_mutex;
@ -324,6 +326,7 @@ meta_thread_init (MetaThread *thread)
MetaThreadPrivate *priv = meta_thread_get_instance_private (thread);
g_mutex_init (&priv->callbacks_mutex);
priv->main_thread = g_thread_self ();
}
void
@ -665,7 +668,10 @@ meta_thread_run_impl_task_sync (MetaThread *thread,
switch (priv->thread_type)
{
case META_THREAD_TYPE_USER:
return run_impl_task_sync_user (thread, func, user_data, error);
if (priv->main_thread == g_thread_self ())
return run_impl_task_sync_user (thread, func, user_data, error);
else
return run_impl_task_sync_kernel (thread, func, user_data, error);
case META_THREAD_TYPE_KERNEL:
return run_impl_task_sync_kernel (thread, func, user_data, error);
}