From 499e248d4cac5ac8f230b9cadbf6dd313d23987e Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Wed, 18 Sep 2019 15:30:03 +1000 Subject: [PATCH] egl: Fix racyness in display thread creation Multiple different scenarios could break the display thread creation and end up blocking waiting for thread o be created. Fix them all by correctly waiting for a new boolean to become valid. --- gst-libs/gst/vaapi/gstvaapiutils_egl.c | 9 ++++++++- gst-libs/gst/vaapi/gstvaapiutils_egl.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gst-libs/gst/vaapi/gstvaapiutils_egl.c b/gst-libs/gst/vaapi/gstvaapiutils_egl.c index 801aef2b8d..0c2a1f5a11 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_egl.c +++ b/gst-libs/gst/vaapi/gstvaapiutils_egl.c @@ -573,6 +573,7 @@ egl_display_thread (gpointer data) EGLint major_version, minor_version; gchar **gl_apis, **gl_api; + g_mutex_lock (&display->mutex); if (!display->base.is_wrapped) { gl_display = display->base.handle.p = egl_get_display_from_native (display->base.handle.u, @@ -609,7 +610,9 @@ egl_display_thread (gpointer data) goto error; display->base.is_valid = TRUE; + display->created = TRUE; g_cond_broadcast (&display->gl_thread_ready); + g_mutex_unlock (&display->mutex); while (!display->gl_thread_cancel) { EglMessage *const msg = @@ -624,17 +627,20 @@ egl_display_thread (gpointer data) egl_object_unref (msg); } } + g_mutex_lock (&display->mutex); done: if (gl_display != EGL_NO_DISPLAY && !display->base.is_wrapped) eglTerminate (gl_display); display->base.handle.p = NULL; g_cond_broadcast (&display->gl_thread_ready); + g_mutex_unlock (&display->mutex); return NULL; /* ERRORS */ error: { + display->created = TRUE; display->base.is_valid = FALSE; goto done; } @@ -656,7 +662,8 @@ egl_display_init (EglDisplay * display) return FALSE; g_mutex_lock (&display->mutex); - g_cond_wait (&display->gl_thread_ready, &display->mutex); + while (!display->created) + g_cond_wait (&display->gl_thread_ready, &display->mutex); g_mutex_unlock (&display->mutex); return display->base.is_valid; } diff --git a/gst-libs/gst/vaapi/gstvaapiutils_egl.h b/gst-libs/gst/vaapi/gstvaapiutils_egl.h index 2dcdf6836b..abf3735e7b 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_egl.h +++ b/gst-libs/gst/vaapi/gstvaapiutils_egl.h @@ -122,6 +122,7 @@ struct egl_display_s GCond gl_thread_ready; volatile gboolean gl_thread_cancel; GAsyncQueue *gl_queue; + gboolean created; }; struct egl_config_s