[vlc-commits] libvlc: media_list: use vlc_atomic_rc for refcount
Alexandre Janniaux
git at videolan.org
Thu Dec 10 13:39:38 UTC 2020
vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Sat Nov 21 11:23:19 2020 +0100| [b39bbfee2de1b8eb5e4d554c80e82509fb1d510a] | committer: Alexandre Janniaux
libvlc: media_list: use vlc_atomic_rc for refcount
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b39bbfee2de1b8eb5e4d554c80e82509fb1d510a
---
lib/media_list.c | 18 +++++-------------
lib/media_list_internal.h | 3 +--
2 files changed, 6 insertions(+), 15 deletions(-)
diff --git a/lib/media_list.c b/lib/media_list.c
index c747778d47..353530c2a5 100644
--- a/lib/media_list.c
+++ b/lib/media_list.c
@@ -33,6 +33,7 @@
#include <vlc/libvlc_events.h>
#include <vlc_common.h>
+#include <vlc_atomic.h>
#include "libvlc_internal.h"
#include "media_internal.h" // libvlc_media_new_from_input_item()
@@ -161,11 +162,10 @@ libvlc_media_list_t *libvlc_media_list_new(void)
p_mlist->b_read_only = false;
vlc_mutex_init( &p_mlist->object_lock );
- vlc_mutex_init( &p_mlist->refcount_lock ); // FIXME: spinlock?
+ vlc_atomic_rc_init( &p_mlist->rc );
vlc_array_init( &p_mlist->items );
assert( p_mlist->items.i_count == 0 );
- p_mlist->i_refcount = 1;
p_mlist->p_md = NULL;
p_mlist->p_internal_md = NULL;
@@ -179,14 +179,8 @@ libvlc_media_list_t *libvlc_media_list_new(void)
**************************************************************************/
void libvlc_media_list_release( libvlc_media_list_t * p_mlist )
{
- vlc_mutex_lock( &p_mlist->refcount_lock );
- p_mlist->i_refcount--;
- if( p_mlist->i_refcount > 0 )
- {
- vlc_mutex_unlock( &p_mlist->refcount_lock );
- return;
- }
- vlc_mutex_unlock( &p_mlist->refcount_lock );
+ if( !vlc_atomic_rc_dec( &p_mlist->rc ) )
+ return
/* Refcount null, time to free */
@@ -211,9 +205,7 @@ void libvlc_media_list_release( libvlc_media_list_t * p_mlist )
**************************************************************************/
void libvlc_media_list_retain( libvlc_media_list_t * p_mlist )
{
- vlc_mutex_lock( &p_mlist->refcount_lock );
- p_mlist->i_refcount++;
- vlc_mutex_unlock( &p_mlist->refcount_lock );
+ vlc_atomic_rc_inc( &p_mlist->rc );
}
/**************************************************************************
diff --git a/lib/media_list_internal.h b/lib/media_list_internal.h
index 82c1482148..0fda98d895 100644
--- a/lib/media_list_internal.h
+++ b/lib/media_list_internal.h
@@ -36,9 +36,8 @@
struct libvlc_media_list_t
{
libvlc_event_manager_t event_manager;
- int i_refcount;
vlc_mutex_t object_lock;
- vlc_mutex_t refcount_lock;
+ vlc_atomic_rc_t rc;
libvlc_media_t * p_md; /* The media from which the
* mlist comes, if any. */
libvlc_media_t * p_internal_md; /* media set from media.c */
More information about the vlc-commits
mailing list