[vlc-devel] [PATCH 3/3] thread: optimize the one-time initializer

Thomas Guillem thomas at gllm.fr
Thu Apr 2 16:37:58 CEST 2020



On Thu, Apr 2, 2020, at 16:28, RĂ©mi Denis-Courmont wrote:
> ---
>  include/vlc_threads.h | 7 +++++++
>  src/misc/threads.c    | 4 +++-
>  2 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/include/vlc_threads.h b/include/vlc_threads.h
> index 87d0691402..98ee823197 100644
> --- a/include/vlc_threads.h
> +++ b/include/vlc_threads.h
> @@ -642,6 +642,13 @@ typedef struct
>   * \param cb callback to execute (the first time)
>   */
>  VLC_API void vlc_once(vlc_once_t *restrict once, void (*cb)(void));
> +
> +static inline void vlc_once_inline(vlc_once_t *restrict once, void (*cb)(void))
> +{
> +    if (unlikely(atomic_load_explicit(&once->value, memory_order_acquire) < 3))

A comment explaining this value could be welcome.
It's pretty obvious when you read the diff, but if you read only the header it might be confusing.

OK for the set.

> +        vlc_once(once, cb);
> +}
> +#define vlc_once(once, cb) vlc_once_inline(once, cb)
>  #endif
>  
>  /**
> diff --git a/src/misc/threads.c b/src/misc/threads.c
> index 945b9568f6..e26a98f7cd 100644
> --- a/src/misc/threads.c
> +++ b/src/misc/threads.c
> @@ -536,7 +536,9 @@ int vlc_sem_timedwait(vlc_sem_t *sem, vlc_tick_t deadline)
>  
>  enum { VLC_ONCE_UNDONE, VLC_ONCE_DOING, VLC_ONCE_CONTEND, VLC_ONCE_DONE };
>  
> -void vlc_once(vlc_once_t *restrict once, void (*cb)(void))
> +static_assert (VLC_ONCE_DONE == 3, "Check vlc_once in header file");
> +
> +void (vlc_once)(vlc_once_t *restrict once, void (*cb)(void))
>  {
>      unsigned int value = VLC_ONCE_UNDONE;
>  
> -- 
> 2.26.0
> 
> _______________________________________________
> 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