[vlc-devel] [PATCH] posix/wait: Fix timespec calculation

Alexandre Janniaux ajanni at videolabs.io
Mon Mar 9 09:35:46 CET 2020


I disagree for this form, it introduces double negation
which is almost always more confusing. Better swap the
now_from/now_to and replace the minus sign by a plus if
you want parenthesis.

A better variant for what you want regarding this would be
to have `elapsed_sec/nsec` intermediate variables for:
now_to.tv_nsec - now_from.tv_nsec
and
now_to.tv_sec - now_from.tv_sec

and use them in the lldiv instead. It's not much but it might
ease the reading by splitting the steps vertically instead of
having to process them together.

Regards,
--
Alexandre Janniaux
Videolabs

On Mon, Mar 09, 2020 at 08:06:40AM +0100, Steve Lhomme wrote:
> I think parenthesis like this would be clearer:
> - (now_from.tv_nsec - now_to.tv_nsec)
>
> It may also be less prone to overflow.
>
> On 2020-03-07 11:45, Marvin Scholz wrote:
> > ---
> >   src/posix/wait.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/src/posix/wait.c b/src/posix/wait.c
> > index a6d58d721b..dfb0c508db 100644
> > --- a/src/posix/wait.c
> > +++ b/src/posix/wait.c
> > @@ -119,7 +119,7 @@ static void vlc_timespec_adjust(clockid_t cid, struct timespec *restrict ts)
> >       clock_gettime(vlc_clock_id, &now_to);
> >       d = lldiv((ts->tv_sec - now_from.tv_sec + now_to.tv_sec) * 1000000000LL
> > -              + ts->tv_nsec - now_from.tv_nsec - now_to.tv_nsec, 1000000000LL);
> > +              + ts->tv_nsec - now_from.tv_nsec + now_to.tv_nsec, 1000000000LL);
> >       ts->tv_sec = d.quot;
> >       ts->tv_nsec = d.rem;
> > --
> > 2.21.1 (Apple Git-122.3)
> >
> > _______________________________________________
> > vlc-devel mailing list
> > To unsubscribe or modify your subscription options:
> > https://mailman.videolan.org/listinfo/vlc-devel
> >
> _______________________________________________
> 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