[vlc-devel] [PATCH] vlc_tick: simpler tick<->ns conversion

Thomas Guillem thomas at gllm.fr
Wed Aug 21 11:13:30 CEST 2019


On Wed, Aug 21, 2019, at 10:20, Thomas Guillem wrote:
> NS_FROM_VLC_TICK() could overflow after 1000 days.

Ah no, I checked the wrong #ifdef

We are in this case:
"#elif (1000000000 % CLOCK_FREQ) == 0"
#define NS_FROM_VLC_TICK(vtk)   ((vtk) * (INT64_C(1000000000) / CLOCK_FREQ))"

So, no overflow here. The optimization doesn't worth it since it will be very likely optimized by the compiler.

Please discard this patch.

> ---
>  include/vlc_tick.h | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/include/vlc_tick.h b/include/vlc_tick.h
> index 517eff1a44..1eb1f46cc9 100644
> --- a/include/vlc_tick.h
> +++ b/include/vlc_tick.h
> @@ -147,7 +147,10 @@ static inline vlc_tick_t 
> vlc_tick_from_frac(uint64_t num, uint64_t den)
>  /*
>   * vlc_tick_t <> nanoseconds (ns) conversions
>   */
> -#if (CLOCK_FREQ % 1000000000) == 0
> +#if (CLOCK_FREQ == 1000000)
> +#define VLC_TICK_FROM_NS(ns)    ((ns) / INT64_C(1000))
> +#define NS_FROM_VLC_TICK(vtk)   ((vtk) * INT64_C(1000))
> +#elif (CLOCK_FREQ % 1000000000) == 0
>  #define VLC_TICK_FROM_NS(ns)    ((ns)  * (CLOCK_FREQ / 
> (INT64_C(1000000000))))
>  #define NS_FROM_VLC_TICK(vtk)   ((vtk) / (CLOCK_FREQ / 
> (INT64_C(1000000000))))
>  #elif (1000000000 % CLOCK_FREQ) == 0
> -- 
> 2.20.1
> 
> _______________________________________________
> 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