[vlc-devel] [RFC] vdpau/instance: create the vdp/device under lock
Rémi Denis-Courmont
remi at remlab.net
Wed Nov 27 16:57:07 CET 2019
Reentrancy is the reason IIRC.
Le 27 novembre 2019 13:48:14 GMT+02:00, Steve Lhomme <robux4 at ycbcr.xyz> a écrit :
>There's no reason to unlock before creating more than 1 instance and
>then
>destroying the extra ones. No matter what we'll still return only after
>an instance has been created (or failed to be created). Concurrent
>calls
>for the same display name will only create one instance.
>---
> modules/hw/vdpau/instance.c | 21 ++++++---------------
> 1 file changed, 6 insertions(+), 15 deletions(-)
>
>diff --git a/modules/hw/vdpau/instance.c b/modules/hw/vdpau/instance.c
>index 4a6d27fe5f0..862e63e0e21 100644
>--- a/modules/hw/vdpau/instance.c
>+++ b/modules/hw/vdpau/instance.c
>@@ -129,7 +129,7 @@ static pthread_mutex_t lock =
>PTHREAD_MUTEX_INITIALIZER;
> VdpStatus vdp_get_x11(const char *display_name, int snum,
> vdp_t **restrict vdpp, VdpDevice *restrict devicep)
> {
>- vdp_instance_t *vi, *vi2;
>+ vdp_instance_t *vi;
>
> if (display_name == NULL)
> {
>@@ -140,29 +140,20 @@ VdpStatus vdp_get_x11(const char *display_name,
>int snum,
>
> pthread_mutex_lock(&lock);
> vi = vdp_instance_lookup(display_name, snum);
>- pthread_mutex_unlock(&lock);
> if (vi != NULL)
> goto found;
>
> vi = vdp_instance_create(display_name, snum);
> if (vi == NULL)
>- return VDP_STATUS_ERROR;
>-
>- pthread_mutex_lock(&lock);
>- vi2 = vdp_instance_lookup(display_name, snum);
>- if (unlikely(vi2 != NULL))
>- { /* Another thread created the instance (race condition corner
>case) */
>- pthread_mutex_unlock(&lock);
>- vdp_instance_destroy(vi);
>- vi = vi2;
>- }
>- else
> {
>- vi->next = list;
>- list = vi;
> pthread_mutex_unlock(&lock);
>+ return VDP_STATUS_ERROR;
> }
>+
>+ vi->next = list;
>+ list = vi;
> found:
>+ pthread_mutex_unlock(&lock);
> *vdpp = vi->vdp;
> *devicep = vi->device;
> return VDP_STATUS_OK;
>--
>2.17.1
>
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel
--
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20191127/afd4cf04/attachment.html>
More information about the vlc-devel
mailing list