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.
This commit is contained in:
Matthew Waters 2019-09-18 15:30:03 +10:00
parent 2e8cdac059
commit 499e248d4c
2 changed files with 9 additions and 1 deletions

View file

@ -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;
}

View file

@ -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