[vlc-commits] picture: socialize the reference counter

Rémi Denis-Courmont git at videolan.org
Tue Dec 11 18:11:16 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 10 23:29:55 2018 +0200| [fc809b3a06b06b9cad485bd6e830e9c11df93b7b] | committer: Rémi Denis-Courmont

picture: socialize the reference counter

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

 include/vlc_picture.h | 8 ++++++++
 src/misc/picture.c    | 7 +++----
 src/misc/picture.h    | 1 -
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index 2216e7072f..772bc4fc1d 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -27,6 +27,12 @@
 #define VLC_PICTURE_H 1
 
 #include <assert.h>
+#ifndef __cplusplus
+#include <stdatomic.h>
+#else
+#include <atomic>
+using std::atomic_uintptr_t;
+#endif
 
 /**
  * \file
@@ -112,6 +118,8 @@ struct picture_t
 
     /** Next picture in a FIFO a pictures */
     struct picture_t *p_next;
+
+    atomic_uintptr_t refs;
 };
 
 /**
diff --git a/src/misc/picture.c b/src/misc/picture.c
index 7da1a07035..b97d181aba 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -216,7 +216,7 @@ static picture_priv_t *picture_NewPrivate(const video_format_t *restrict p_fmt,
         return NULL;
     }
 
-    atomic_init( &priv->gc.refs, 1 );
+    atomic_init(&p_picture->refs, 1);
     priv->gc.opaque = NULL;
 
     return priv;
@@ -324,8 +324,7 @@ picture_t *picture_Hold( picture_t *p_picture )
 {
     assert( p_picture != NULL );
 
-    picture_priv_t *priv = (picture_priv_t *)p_picture;
-    uintptr_t refs = atomic_fetch_add( &priv->gc.refs, 1 );
+    uintptr_t refs = atomic_fetch_add(&p_picture->refs, 1);
     assert( refs > 0 );
     return p_picture;
 }
@@ -335,7 +334,7 @@ void picture_Release( picture_t *p_picture )
     assert( p_picture != NULL );
 
     picture_priv_t *priv = (picture_priv_t *)p_picture;
-    uintptr_t refs = atomic_fetch_sub( &priv->gc.refs, 1 );
+    uintptr_t refs = atomic_fetch_sub(&p_picture->refs, 1);
     assert( refs != 0 );
     if( refs > 1 )
         return;
diff --git a/src/misc/picture.h b/src/misc/picture.h
index 633d2a3abb..1215214d69 100644
--- a/src/misc/picture.h
+++ b/src/misc/picture.h
@@ -28,7 +28,6 @@ typedef struct
     picture_t picture;
     struct
     {
-        atomic_uintptr_t refs;
         void (*destroy)(picture_t *);
         void *opaque;
     } gc;



More information about the vlc-commits mailing list