<html><head></head><body>Reentrancy is the reason IIRC.<br><br><div class="gmail_quote">Le 27 novembre 2019 13:48:14 GMT+02:00, Steve Lhomme <robux4@ycbcr.xyz> 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">There's no reason to unlock before creating more than 1 instance and then<br>destroying the extra ones. No matter what we'll still return only after<br>an instance has been created (or failed to be created). Concurrent calls<br>for the same display name will only create one instance.<hr> modules/hw/vdpau/instance.c | 21 ++++++---------------<br> 1 file changed, 6 insertions(+), 15 deletions(-)<br><br>diff --git a/modules/hw/vdpau/instance.c b/modules/hw/vdpau/instance.c<br>index 4a6d27fe5f0..862e63e0e21 100644<br>--- a/modules/hw/vdpau/instance.c<br>+++ b/modules/hw/vdpau/instance.c<br>@@ -129,7 +129,7 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;<br> VdpStatus vdp_get_x11(const char *display_name, int snum,<br>                       vdp_t **restrict vdpp, VdpDevice *restrict devicep)<br> {<br>-    vdp_instance_t *vi, *vi2;<br>+    vdp_instance_t *vi;<br> <br>     if (display_name == NULL)<br>     {<br>@@ -140,29 +140,20 @@ VdpStatus vdp_get_x11(const char *display_name, int snum,<br> <br>     pthread_mutex_lock(&lock);<br>     vi = vdp_instance_lookup(display_name, snum);<br>-    pthread_mutex_unlock(&lock);<br>     if (vi != NULL)<br>         goto found;<br> <br>     vi = vdp_instance_create(display_name, snum);<br>     if (vi == NULL)<br>-        return VDP_STATUS_ERROR;<br>-<br>-    pthread_mutex_lock(&lock);<br>-    vi2 = vdp_instance_lookup(display_name, snum);<br>-    if (unlikely(vi2 != NULL))<br>-    {   /* Another thread created the instance (race condition corner case) */<br>-        pthread_mutex_unlock(&lock);<br>-        vdp_instance_destroy(vi);<br>-        vi = vi2;<br>-    }<br>-    else<br>     {<br>-        vi->next = list;<br>-        list = vi;<br>         pthread_mutex_unlock(&lock);<br>+        return VDP_STATUS_ERROR;<br>     }<br>+<br>+    vi->next = list;<br>+    list = vi;<br> found:<br>+    pthread_mutex_unlock(&lock);<br>     *vdpp = vi->vdp;<br>     *devicep = vi->device;<br>     return VDP_STATUS_OK;</pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>