From 7306f2de2c753c90330c24c109bec81cbe16b6e3 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Mon, 28 Nov 2016 14:22:05 +1100 Subject: [PATCH] glwindow: move g_main_context_push/pop_thread_default() to run() Calling g_main_context_push_thread and then g_main_context_invoke() (used by gst_gl_window_send_message_async()) in the same thread will cause the invoked function to run immediately instead of being delayed. This had implications for the creation of the OpenGL context not waiting until the main loop had completely started up and as a result would sometimes deadlock in short create/destroy scenarios. https://bugzilla.gnome.org/show_bug.cgi?id=775171 --- gst-libs/gst/gl/gstglwindow.c | 47 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/gst-libs/gst/gl/gstglwindow.c b/gst-libs/gst/gl/gstglwindow.c index 8e0f880..5752ae2 100644 --- a/gst-libs/gst/gl/gstglwindow.c +++ b/gst-libs/gst/gl/gstglwindow.c @@ -134,35 +134,12 @@ gst_gl_window_error_quark (void) static gboolean gst_gl_window_default_open (GstGLWindow * window, GError ** error) { - GstGLWindowPrivate *priv = window->priv; - - if (g_main_context_get_thread_default ()) { - if (priv->main_context) - g_main_context_unref (priv->main_context); - if (priv->loop) - g_main_loop_unref (priv->loop); - priv->main_context = g_main_context_ref_thread_default (); - priv->loop = NULL; - priv->alive = TRUE; - } else { - g_main_context_push_thread_default (priv->main_context); - } - return TRUE; } static void gst_gl_window_default_close (GstGLWindow * window) { - GstGLWindowPrivate *priv = window->priv; - - if (!priv->loop) { - priv->alive = FALSE; - g_main_context_unref (priv->main_context); - priv->main_context = NULL; - } else { - g_main_context_pop_thread_default (priv->main_context); - } } static void @@ -505,7 +482,29 @@ gst_gl_window_show (GstGLWindow * window) static void gst_gl_window_default_run (GstGLWindow * window) { - g_main_loop_run (window->priv->loop); + GstGLWindowPrivate *priv = window->priv; + + if (g_main_context_get_thread_default ()) { + if (priv->main_context) + g_main_context_unref (priv->main_context); + if (priv->loop) + g_main_loop_unref (priv->loop); + priv->main_context = g_main_context_ref_thread_default (); + priv->loop = NULL; + priv->alive = TRUE; + } else { + g_main_context_push_thread_default (priv->main_context); + } + + g_main_loop_run (priv->loop); + + if (!priv->loop) { + priv->alive = FALSE; + g_main_context_unref (priv->main_context); + priv->main_context = NULL; + } else { + g_main_context_pop_thread_default (priv->main_context); + } } /** -- 2.7.4