Skip to contentSkip to conversation

weston: gal2d-renderer: Fix deadlock on exit

PATCH In review Richard Röjfors 2 participants 2 messages Jan 18, 2016 – Mar 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 weston: gal2d-renderer: Fix deadlock on exit

There is a race between the worker thread flipping the buffers and the main thread on exit, this patch fixes that.

---
 ...002-gal2d-renderer-Avoid-deadlock-on-exit.patch | 69 ++++++++++++++++++++++ recipes-graphics/wayland/weston_%.bbappend         |  5 +-

 2 files changed, 73 insertions(+), 1 deletion(-)

 create mode 100644 recipes-graphics/wayland/weston/0002-gal2d-renderer-Avoid-deadlock-on-exit.patch

recipes-graphics/wayland/weston/0002-gal2d-renderer-Avoid-deadlock-on-exit.patch new file +69 -0
new file mode 100644
index 0000000..cb6478d
@@ -0,0 +1,69 @@
+From e032db2353427d174924f456a39c58de374acb33 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Richard=20R=C3=B6jfors?= <[email protected]>
+Date: Wed, 13 Jan 2016 21:04:08 +0100
+Subject: [PATCH] gal2d-renderer: Avoid deadlock on exit
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The way the worker thread was shut down was a bit racy.
+Make sure to set the flag indicating the thread to stop spinning
+before waking up the thread.
+
+Upstream-Status: Pending
+
+Signed-off-by: Richard Röjfors <[email protected]>
+---
+ src/gal2d-renderer.c | 20 ++++++++++----------
+ 1 file changed, 10 insertions(+), 10 deletions(-)
+
+diff --git a/src/gal2d-renderer.c b/src/gal2d-renderer.c
+index 7ebbf98..d2a29ff 100644
+--- a/src/gal2d-renderer.c
++++ b/src/gal2d-renderer.c
+@@ -495,21 +495,21 @@ static void *gal2d_output_worker(void *arg)
+ {
+     struct weston_output *output = (struct weston_output *)arg;
+     struct gal2d_output_state *go = get_output_state(output);
++    int go_on = 1;
+ 
+-    while(1)
++    while(go_on)
+     {
+-        if(gcoOS_WaitSignal(gcvNULL, go->signal, gcvINFINITE) == gcvSTATUS_OK )
++        int ok = gcoOS_WaitSignal(gcvNULL, go->signal, gcvINFINITE) == gcvSTATUS_OK;
++
++        pthread_mutex_lock(&go->workerMutex);
++        go_on = go->exitWorker == 0;
++        pthread_mutex_unlock(&go->workerMutex);
++
++        if (ok && go_on)
+         {
+             gal2d_flip_surface(output);
+             gcoOS_Signal(gcvNULL,go->busySignal, gcvTRUE);
+         }
+-        pthread_mutex_lock(&go->workerMutex);
+-        if(go->exitWorker == 1)
+-        {
+-            pthread_mutex_unlock(&go->workerMutex);
+-            break;
+-        }
+-        pthread_mutex_unlock(&go->workerMutex);
+     }
+     return 0;
+ }
+@@ -1169,10 +1169,10 @@ gal2d_renderer_output_destroy(struct weston_output *output)
+ 	}
+     else
+     {
+-        gcoOS_Signal(gcvNULL,go->signal, gcvTRUE);
+         pthread_mutex_lock(&go->workerMutex);
+         go->exitWorker = 1;
+         pthread_mutex_unlock(&go->workerMutex);
++        gcoOS_Signal(gcvNULL,go->signal, gcvTRUE);
+         pthread_join(go->workerId, NULL);
+     }
+ 
+-- 
+2.5.0
+
recipes-graphics/wayland/weston_%.bbappend +0 -0
index a7496da..f41b5af 100644
@@ -1,6 +1,9 @@

 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

-SRC_URI_append_mx6 = " file://0001-MGS-840-Add-i.MX6-support-for-weston.patch" +SRC_URI_append_mx6 = " \
+    file://0001-MGS-840-Add-i.MX6-support-for-weston.patch \
+    file://0002-gal2d-renderer-Avoid-deadlock-on-exit.patch \
+"

 PACKAGECONFIG_append_mx6q = " cairo-glesv2" PACKAGECONFIG_append_mx6dl = " cairo-glesv2"

Signature · 1 line
2.5.0
#1 lore raw

Hello Richard,

Quoted 4 lines · Richard Röjfors

There is a race between the worker thread flipping the buffers and the main thread on exit, this patch fixes that.

We finished the upgrade for 3.14.52 BSP. Is it possible for you to prepare the pending fixes patchset on top of master and later jethro?/

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750