[PATCH weston] simple-egl: Avoid race condition.

Scott Moreau oreaus at gmail.com
Fri Aug 31 02:18:15 PDT 2012


After explaining the problem on irc, Pekka dictated this solution which works.
The problem is that simple-egl can hang when toggling fullscreen because of a
race where (quoting Pekka) "if it dispatches the frame callback simple-egl
itself requested before the Mesa's own frame callback came, simple-egl will go
to its redraw routing and call eglSwapBuffers so you end up effectively calling
eglSwapBuffers from within eglSwapBuffers, and deadlock". This patch avoids
redrawing (which calls eglSwapBuffers) when there is a pending frame callback.
---
 clients/simple-egl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/clients/simple-egl.c b/clients/simple-egl.c
index c52c82c..de93e09 100644
--- a/clients/simple-egl.c
+++ b/clients/simple-egl.c
@@ -264,7 +264,9 @@ configure_callback(void *data, struct wl_callback *callback, uint32_t  time)
 	wl_callback_destroy(callback);
 
 	window->configured = 1;
-	redraw(data, NULL, time);
+
+	if (window->callback == NULL)
+		redraw(data, NULL, time);
 }
 
 static struct wl_callback_listener configure_callback_listener = {
@@ -363,6 +365,9 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
 	static uint32_t start_time = 0;
 	struct wl_region *region;
 
+	assert(window->callback == callback);
+	window->callback = NULL;
+
 	if (callback)
 		wl_callback_destroy(callback);
 
-- 
1.7.11.4



More information about the wayland-devel mailing list