[vlc-devel] [vlc-commits] input: add reference count

Thomas Guillem thomas at gllm.fr
Sun Mar 17 09:43:45 CET 2019


This could be reverted when the input is not exposed anymore.

On Sun, Mar 17, 2019, at 02:39, Rémi Denis-Courmont wrote:
> vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Mar 
> 16 10:36:13 2019 +0200| [4cd0b49ee75039ea7af2ef7ff38ea4d3678c5db5] | 
> committer: Rémi Denis-Courmont
> 
> input: add reference count
> 
> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4cd0b49ee75039ea7af2ef7ff38ea4d3678c5db5
> ---
> 
>  src/input/input.c          | 16 ++++++++++++----
>  src/input/input_internal.h |  1 +
>  2 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/src/input/input.c b/src/input/input.c
> index 9a2500735f..c562ad04a3 100644
> --- a/src/input/input.c
> +++ b/src/input/input.c
> @@ -232,7 +232,7 @@ void input_Close( input_thread_t *p_input )
>      if( input_priv(p_input)->is_running )
>          vlc_join( input_priv(p_input)->thread, NULL );
>      vlc_interrupt_deinit( &input_priv(p_input)->interrupt );
> -    vlc_object_delete(p_input);
> +    input_Release(p_input);
>  }
>  
>  void input_SetTime( input_thread_t *p_input, vlc_tick_t i_time, bool b_fast )
> @@ -513,19 +513,27 @@ static input_thread_t *Create( vlc_object_t *p_parent,
>  
>      /* Set the destructor when we are sure we are initialized */
>      vlc_object_set_destructor( p_input, input_Destructor );
> -
> +    atomic_init(&priv->refs, 0);
>      return p_input;
>  }
>  
>  input_thread_t *input_Hold(input_thread_t *input)
>  {
> -    (vlc_object_hold)(VLC_OBJECT(input));
> +    input_thread_private_t *priv = input_priv(input);
> +
> +    atomic_fetch_add_explicit(&priv->refs, 1, memory_order_relaxed);
>      return input;
>  }
>  
>  void input_Release(input_thread_t *input)
>  {
> -    (vlc_object_release)(VLC_OBJECT(input));
> +    input_thread_private_t *priv = input_priv(input);
> +
> +    if (atomic_fetch_sub_explicit(&priv->refs, 1, memory_order_release))
> +        return;
> +
> +    atomic_thread_fence(memory_order_acquire);
> +    vlc_object_delete(VLC_OBJECT(input));
>  }
>  
>  /*****************************************************************************
> diff --git a/src/input/input_internal.h b/src/input/input_internal.h
> index 7fd05c0d64..18495881c2 100644
> --- a/src/input/input_internal.h
> +++ b/src/input/input_internal.h
> @@ -200,6 +200,7 @@ typedef struct input_thread_private_t
>  
>      vlc_thread_t thread;
>      vlc_interrupt_t interrupt;
> +    atomic_uintptr_t refs;
>  } input_thread_private_t;
>  
>  static inline input_thread_private_t *input_priv(input_thread_t *input)
> 
> _______________________________________________
> vlc-commits mailing list
> vlc-commits at videolan.org
> https://mailman.videolan.org/listinfo/vlc-commits
>


More information about the vlc-devel mailing list