[vlc-commits] picture: Use vlc_atomic_rc

Hugo Beauzée-Luyssen git at videolan.org
Thu Dec 17 15:19:48 UTC 2020


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Nov 26 12:29:08 2020 +0100| [9b197f348c6d33f565bf8a205486e55ff41a02ba] | committer: Hugo Beauzée-Luyssen

picture: Use vlc_atomic_rc

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

 include/vlc_picture.h | 19 ++++---------------
 src/misc/picture.c    |  6 ++----
 2 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index 5010c2f10a..09f65a1326 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -26,14 +26,7 @@
 #define VLC_PICTURE_H 1
 
 #include <assert.h>
-#ifndef __cplusplus
-#include <stdatomic.h>
-#else
-#include <atomic>
-using std::atomic_uintptr_t;
-using std::memory_order_relaxed;
-using std::memory_order_release;
-#endif
+#include <vlc_atomic.h>
 
 /**
  * \file
@@ -160,7 +153,7 @@ struct picture_t
     /** Next picture in a FIFO a pictures */
     struct picture_t *p_next;
 
-    atomic_uintptr_t refs;
+    vlc_atomic_rc_t refs;
 };
 
 static inline vlc_video_context* picture_GetVideoContext(picture_t *pic)
@@ -360,8 +353,7 @@ VLC_API void picture_Destroy(picture_t *picture);
  */
 static inline picture_t *picture_Hold(picture_t *picture)
 {
-    atomic_fetch_add_explicit(&picture->refs, (uintptr_t)1,
-                              memory_order_relaxed);
+    vlc_atomic_rc_inc(&picture->refs);
     return picture;
 }
 
@@ -374,10 +366,7 @@ static inline picture_t *picture_Hold(picture_t *picture)
  */
 static inline void picture_Release(picture_t *picture)
 {
-    uintptr_t refs = atomic_fetch_sub_explicit(&picture->refs, (uintptr_t)1,
-                                               memory_order_release);
-    vlc_assert(refs > 0);
-    if (refs == 1)
+    if (vlc_atomic_rc_dec(&picture->refs))
         picture_Destroy(picture);
 }
 
diff --git a/src/misc/picture.c b/src/misc/picture.c
index e00b130325..5b867a7591 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -210,7 +210,7 @@ static bool picture_InitPrivate(const video_format_t *restrict p_fmt,
     if( picture_Setup( p_picture, p_fmt ) )
         return false;
 
-    atomic_init(&p_picture->refs, 1);
+    vlc_atomic_rc_init(&p_picture->refs);
     priv->gc.opaque = NULL;
 
     p_picture->p_sys = p_resource->p_sys;
@@ -337,9 +337,7 @@ picture_t *picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_
 
 void picture_Destroy(picture_t *picture)
 {
-    /* See changes from other threads */
-    atomic_thread_fence(memory_order_acquire);
-    assert(atomic_load_explicit(&picture->refs, memory_order_relaxed) == 0);
+    assert(vlc_atomic_rc_get(&picture->refs) == 0);
 
     PictureDestroyContext(picture);
 



More information about the vlc-commits mailing list