[vlc-devel] [PATCH 1/4] libvlc: media_list: use vlc_atomic_rc for refcount

Romain Vimont rom1v at videolabs.io
Mon Nov 23 11:14:03 CET 2020


Patchset LGTM.

On Sat, Nov 21, 2020 at 01:20:58PM +0100, Alexandre Janniaux wrote:
> ---
>  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 */
> -- 
> 2.29.2
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list