> On Jun 19, 2020, at 12:40, Paul Irofti <[email protected]> wrote:
>
> [...]
>
> +
> +static inline void
> +bintimeaddfrac(const struct bintime *bt, uint64_t x, struct bintime *ct)
> +{
> + ct->sec = bt->sec;
> + if (bt->frac > bt->frac + x)
> + ct->sec++;
> + ct->frac = bt->frac + x;
> +}
> +
> +static inline void
> +BINTIME_TO_TIMESPEC(const struct bintime *bt, struct timespec *ts)
> +{
> + ts->tv_sec = bt->sec;
> + ts->tv_nsec = (long)(((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32))
> >> 32);
> +}
> +
> +static inline void
> +BINTIME_TO_TIMEVAL(const struct bintime *bt, struct timeval *tv)
> +{
> + tv->tv_sec = bt->sec;
> + tv->tv_usec = (long)(((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >>
> 32);
> +}
Is it possible to use the definitions in
sys/time.h for these?
> +
> +static inline void
> +bintimeadd(const struct bintime *bt, const struct bintime *ct,
> + struct bintime *dt)
> +{
> + dt->sec = bt->sec + ct->sec;
> + if (bt->frac > bt->frac + ct->frac)
> + dt->sec++;
> + dt->frac = bt->frac + ct->frac;
> +}
> +
> +static inline void
> +bintimesub(const struct bintime *bt, const struct bintime *ct,
> + struct bintime *dt)
> +{
> + dt->sec = bt->sec - ct->sec;
> + if (bt->frac < bt->frac - ct->frac)
> + dt->sec--;
> + dt->frac = bt->frac - ct->frac;
> +}
Same thing here.