[vlc-devel] [PATCH 1/2] aout: use vlc_atomic_rc_t

quentin.chateau at deepskycorp.com quentin.chateau at deepskycorp.com
Fri Feb 21 15:14:34 CET 2020


From: Quentin Chateau <quentin.chateau at deepskycorp.com>

---
 src/audio_output/aout_internal.h | 3 ++-
 src/audio_output/output.c        | 7 ++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index 57b4f3264d..8b563012e2 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -25,6 +25,7 @@
 
 # include <stdatomic.h>
 
+# include <vlc_atomic.h>
 # include <vlc_viewpoint.h>
 # include "../clock/clock.h"
 
@@ -97,7 +98,7 @@ typedef struct
     atomic_uint buffers_played;
     atomic_uchar restart;
 
-    atomic_uintptr_t refs;
+    vlc_atomic_rc_t rc;
 } aout_owner_t;
 
 typedef struct
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 526489e5f6..60b11081b4 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -30,6 +30,7 @@
 #include <vlc_common.h>
 #include <vlc_aout.h>
 #include <vlc_modules.h>
+#include <vlc_atomic.h>
 
 #include "libvlc.h"
 #include "aout_internal.h"
@@ -222,7 +223,7 @@ audio_output_t *aout_New (vlc_object_t *parent)
     vlc_mutex_init (&owner->vp.lock);
     vlc_viewpoint_init (&owner->vp.value);
     atomic_init (&owner->vp.update, false);
-    atomic_init(&owner->refs, 0);
+    vlc_atomic_rc_init(&owner->rc);
 
     /* Audio output module callbacks */
     var_Create (aout, "volume", VLC_VAR_FLOAT);
@@ -347,7 +348,7 @@ audio_output_t *aout_Hold(audio_output_t *aout)
 {
     aout_owner_t *owner = aout_owner(aout);
 
-    atomic_fetch_add_explicit(&owner->refs, 1, memory_order_relaxed);
+    vlc_atomic_rc_inc(&owner->rc);
     return aout;
 }
 
@@ -380,7 +381,7 @@ void aout_Release(audio_output_t *aout)
 {
     aout_owner_t *owner = aout_owner(aout);
 
-    if (atomic_fetch_sub_explicit(&owner->refs, 1, memory_order_release))
+    if (!vlc_atomic_rc_dec(&owner->rc))
         return;
 
     atomic_thread_fence(memory_order_acquire);
-- 
2.17.1



More information about the vlc-devel mailing list