[vlc-devel] [PATCH 2/3] picture: Use vlc_atomic_rc

Hugo Beauzée-Luyssen hugo at beauzee.fr
Tue Dec 15 17:53:18 CET 2020


---
 include/vlc_picture.h | 19 ++++---------------
 src/misc/picture.c    |  3 +--
 2 files changed, 5 insertions(+), 17 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..60d655d3f9 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;
@@ -339,7 +339,6 @@ 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);
 
     PictureDestroyContext(picture);
 
-- 
2.29.2



More information about the vlc-devel mailing list