[vlc-devel] [vlc-commits] picture: socialize the reference counter

Steve Lhomme robux4 at ycbcr.xyz
Wed Dec 12 10:10:41 CET 2018


On 11/12/2018 18:11, Rémi Denis-Courmont wrote:
> vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 10 23:29:55 2018 +0200| [fc809b3a06b06b9cad485bd6e830e9c11df93b7b] | committer: Rémi Denis-Courmont
>
> picture: socialize the reference counter
>
>> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fc809b3a06b06b9cad485bd6e830e9c11df93b7b
> ---
>
>   include/vlc_picture.h | 8 ++++++++
>   src/misc/picture.c    | 7 +++----
>   src/misc/picture.h    | 1 -
>   3 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/include/vlc_picture.h b/include/vlc_picture.h
> index 2216e7072f..772bc4fc1d 100644
> --- a/include/vlc_picture.h
> +++ b/include/vlc_picture.h
> @@ -27,6 +27,12 @@
>   #define VLC_PICTURE_H 1
>   
>   #include <assert.h>
> +#ifndef __cplusplus
> +#include <stdatomic.h>
> +#else
> +#include <atomic>
> +using std::atomic_uintptr_t;
> +#endif

Is this safe for Objective-C to use these types created in C or C++ ? 
(apparently they are interoperable between C and C++).

>   
>   /**
>    * \file
> @@ -112,6 +118,8 @@ struct picture_t
>   
>       /** Next picture in a FIFO a pictures */
>       struct picture_t *p_next;
> +
> +    atomic_uintptr_t refs;
>   };
>   
>   /**
> diff --git a/src/misc/picture.c b/src/misc/picture.c
> index 7da1a07035..b97d181aba 100644
> --- a/src/misc/picture.c
> +++ b/src/misc/picture.c
> @@ -216,7 +216,7 @@ static picture_priv_t *picture_NewPrivate(const video_format_t *restrict p_fmt,
>           return NULL;
>       }
>   
> -    atomic_init( &priv->gc.refs, 1 );
> +    atomic_init(&p_picture->refs, 1);
>       priv->gc.opaque = NULL;
>   
>       return priv;
> @@ -324,8 +324,7 @@ picture_t *picture_Hold( picture_t *p_picture )
>   {
>       assert( p_picture != NULL );
>   
> -    picture_priv_t *priv = (picture_priv_t *)p_picture;
> -    uintptr_t refs = atomic_fetch_add( &priv->gc.refs, 1 );
> +    uintptr_t refs = atomic_fetch_add(&p_picture->refs, 1);
>       assert( refs > 0 );
>       return p_picture;
>   }
> @@ -335,7 +334,7 @@ void picture_Release( picture_t *p_picture )
>       assert( p_picture != NULL );
>   
>       picture_priv_t *priv = (picture_priv_t *)p_picture;
> -    uintptr_t refs = atomic_fetch_sub( &priv->gc.refs, 1 );
> +    uintptr_t refs = atomic_fetch_sub(&p_picture->refs, 1);
>       assert( refs != 0 );
>       if( refs > 1 )
>           return;
> diff --git a/src/misc/picture.h b/src/misc/picture.h
> index 633d2a3abb..1215214d69 100644
> --- a/src/misc/picture.h
> +++ b/src/misc/picture.h
> @@ -28,7 +28,6 @@ typedef struct
>       picture_t picture;
>       struct
>       {
> -        atomic_uintptr_t refs;
>           void (*destroy)(picture_t *);
>           void *opaque;
>       } gc;
>
> _______________________________________________
> vlc-commits mailing list
> vlc-commits at videolan.org
> https://mailman.videolan.org/listinfo/vlc-commits



More information about the vlc-devel mailing list