<html><head></head><body>Without the surrounding code, I come to think that a semaphore would be far simpler here.<br><br><div class="gmail_quote">Le 7 avril 2020 11:20:01 GMT+03:00, Alexandre Janniaux <ajanni@videolabs.io> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">When using wl_display_dispatch, there is a race condition with the main<br>loop, in which the condition `(!sys->wm.configured)` would have been<br>checked as true, but the event dispatched from the main thread after<br>that so wl_display_dispatch would block indefinitely.<br><br>Said differently, wl_display_dispatch should not be called from a<br>different thread than the main thread (in wayland terms).<br><br>By using a condition variable instead, we let the main thread unblock<br>the vout_window_Enable and prevent this deadlock when the callback for<br>the configured event is called. In addition, it adds the correct lock<br>around the updates and reads of the wm.configured boolean.<br><br>Fixes #24586<hr> modules/video_output/wayland/xdg-shell.c | 10 +++++++++-<br> 1 file changed, 9 insertions(+), 1 deletion(-)<br><br>diff --git a/modules/video_output/wayland/xdg-shell.c b/modules/video_output/wayland/xdg-shell.c<br>index 765ffb2a2f..0b0eba0be0 100644<br>--- a/modules/video_output/wayland/xdg-shell.c<br>+++ b/modules/video_output/wayland/xdg-shell.c<br>@@ -106,6 +106,7 @@ typedef struct<br>     struct wl_surface *cursor_surface;<br> <br>     vlc_mutex_t lock;<br>+    vlc_cond_t cond_configured;<br>     vlc_thread_t thread;<br> } vout_window_sys_t;<br> <br>@@ -262,8 +263,10 @@ static int Enable(vout_window_t *wnd, const vout_window_cfg_t *restrict cfg)<br>     wl_display_flush(display);<br> <br> #ifdef XDG_SHELL<br>+    vlc_mutex_lock(&sys->lock);<br>     while (!sys->wm.configured)<br>-        wl_display_dispatch(display);<br>+        vlc_cond_wait(&sys->cond_configured, &sys->lock);<br>+    vlc_mutex_unlock(&sys->lock);<br> #endif<br> <br>     return VLC_SUCCESS;<br>@@ -339,7 +342,11 @@ static void xdg_surface_configure_cb(void *data, struct xdg_surface *surface,<br>         vout_window_ReportWindowed(wnd);<br> <br>     xdg_surface_ack_configure(surface, serial);<br>+<br>+    vlc_mutex_lock(&sys->lock);<br>     sys->wm.configured = true;<br>+    vlc_cond_signal(&sys->cond_configured);<br>+    vlc_mutex_unlock(&sys->lock);<br> }<br> <br> static const struct xdg_surface_listener xdg_surface_cbs =<br>@@ -617,6 +624,7 @@ static int Open(vout_window_t *wnd)<br>     sys->cursor_theme = NULL;<br>     sys->cursor_surface = NULL;<br>     vlc_mutex_init(&sys->lock);<br>+    vlc_cond_init(&sys->cond_configured);<br>     wnd->sys = sys;<br>     wnd->handle.wl = NULL;<br> </pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>