summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Waters <matthew@centricular.com>2019-09-18 15:30:03 +1000
committerTim-Philipp Müller <tim@centricular.com>2019-09-19 13:50:06 +0100
commit1145dd89548ece83ab17c165ce637d6ec7551776 (patch)
treef0c45a7bbb41ad074aab66b0d1e3445624ea1dc9
parent2e43a67a30293fbd36823420bbf92f4b85ff7451 (diff)
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.
-rw-r--r--gst-libs/gst/vaapi/gstvaapiutils_egl.c9
-rw-r--r--gst-libs/gst/vaapi/gstvaapiutils_egl.h1
2 files changed, 9 insertions, 1 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapiutils_egl.c b/gst-libs/gst/vaapi/gstvaapiutils_egl.c
index 801aef2b..0c2a1f5a 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 2dcdf683..abf3735e 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