[vlc-commits] aout: add reference count
Rémi Denis-Courmont
git at videolan.org
Sun Mar 17 02:39:11 CET 2019
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Mar 16 10:56:09 2019 +0200| [829437ddb2dfcec12b3d0cd87235a9b094c51b07] | committer: Rémi Denis-Courmont
aout: add reference count
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=829437ddb2dfcec12b3d0cd87235a9b094c51b07
---
src/audio_output/aout_internal.h | 2 ++
src/audio_output/output.c | 15 ++++++++++++---
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index 1dd92e96aa..9073988ae6 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -84,6 +84,8 @@ typedef struct
atomic_uint buffers_lost;
atomic_uint buffers_played;
atomic_uchar restart;
+
+ atomic_uintptr_t refs;
} aout_owner_t;
typedef struct
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 3eaa415976..33a73bb3d1 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -244,6 +244,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_object_set_destructor (aout, aout_Destructor);
@@ -365,7 +366,9 @@ audio_output_t *aout_New (vlc_object_t *parent)
audio_output_t *aout_Hold(audio_output_t *aout)
{
- (vlc_object_hold)(VLC_OBJECT(aout));
+ aout_owner_t *owner = aout_owner(aout);
+
+ atomic_fetch_add_explicit(&owner->refs, 1, memory_order_relaxed);
return aout;
}
@@ -391,12 +394,18 @@ void aout_Destroy (audio_output_t *aout)
var_SetFloat (aout, "volume", -1.f);
var_DelCallback(aout, "volume", var_Copy, vlc_object_parent(aout));
var_DelCallback (aout, "stereo-mode", StereoModeCallback, NULL);
- vlc_object_delete(aout);
+ aout_Release(aout);
}
void aout_Release(audio_output_t *aout)
{
- (vlc_object_release)(VLC_OBJECT(aout));
+ aout_owner_t *owner = aout_owner(aout);
+
+ if (atomic_fetch_sub_explicit(&owner->refs, 1, memory_order_release))
+ return;
+
+ atomic_thread_fence(memory_order_acquire);
+ vlc_object_delete(VLC_OBJECT(aout));
}
/**
More information about the vlc-commits
mailing list