[vlc-commits] directx_va: replace the internal reference counter by an atomic value

Steve Lhomme git at videolan.org
Tue Jun 13 15:01:08 CEST 2017


vlc | branch: master | Steve Lhomme <robux4 at videolabs.io> | Mon May 29 15:11:58 2017 +0200| [48dd1615ce66cf800c4851d82bd202026c522737] | committer: Jean-Baptiste Kempf

directx_va: replace the internal reference counter by an atomic value

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=48dd1615ce66cf800c4851d82bd202026c522737
---

 modules/codec/avcodec/directx_va.c | 10 +++++-----
 modules/codec/avcodec/directx_va.h |  3 ++-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index 00b1956055..68b4613a0d 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -355,7 +355,7 @@ int directx_va_Setup(vlc_va_t *va, directx_sys_t *dx_sys, AVCodecContext *avctx)
             dx_sys->surface_count = i;
             return VLC_ENOMEM;
         }
-        surface->refcount = 0;
+        atomic_init(&surface->refcount, 1);
         surface->order = 0;
         surface->p_lock = &dx_sys->surface_lock;
         surface->p_pic = dx_sys->pf_alloc_surface_pic(va, &fmt, i);
@@ -404,7 +404,7 @@ vlc_va_surface_t *directx_va_Get(vlc_va_t *va, directx_sys_t *dx_sys)
 
     for (i = 0; i < dx_sys->surface_count; i++) {
         vlc_va_surface_t *surface = dx_sys->surface[i];
-        if (((old == -1 || surface->order < dx_sys->surface[old]->order)) && !surface->refcount)
+        if (((old == -1 || surface->order < dx_sys->surface[old]->order)) && atomic_load(&surface->refcount))
             old = i;
         if (old_used == -1 || surface->order < dx_sys->surface[old_used]->order)
             old_used = i;
@@ -419,7 +419,7 @@ vlc_va_surface_t *directx_va_Get(vlc_va_t *va, directx_sys_t *dx_sys)
 
     vlc_va_surface_t *surface = dx_sys->surface[i];
 
-    surface->refcount = 1;
+    atomic_store(&surface->refcount,1);
     surface->order = ++dx_sys->surface_order;
     surface->decoderSurface = dx_sys->hw_surface[i];
 
@@ -431,14 +431,14 @@ vlc_va_surface_t *directx_va_Get(vlc_va_t *va, directx_sys_t *dx_sys)
 void directx_va_AddRef(vlc_va_surface_t *surface)
 {
     vlc_mutex_lock( surface->p_lock );
-    surface->refcount++;
+    atomic_fetch_add(&surface->refcount, 1);
     vlc_mutex_unlock( surface->p_lock );
 }
 
 void directx_va_Release(vlc_va_surface_t *surface)
 {
     vlc_mutex_lock( surface->p_lock );
-    surface->refcount--;
+    atomic_fetch_sub(&surface->refcount, 1);
     vlc_mutex_unlock( surface->p_lock );
 }
 
diff --git a/modules/codec/avcodec/directx_va.h b/modules/codec/avcodec/directx_va.h
index 02acddba70..157306e64b 100644
--- a/modules/codec/avcodec/directx_va.h
+++ b/modules/codec/avcodec/directx_va.h
@@ -40,10 +40,11 @@
 #include "va.h"
 
 #include <unknwn.h>
+#include <stdatomic.h>
 
 /* */
 typedef struct {
-    int                refcount;
+    atomic_uintptr_t     refcount;
     unsigned int       order;
     vlc_mutex_t        *p_lock;
     picture_t          *p_pic;



More information about the vlc-commits mailing list