[PATCH weston 1/8] shared: Add timespec_normalize helper

Alexandros Frantzis alexandros.frantzis at collabora.com
Tue Dec 12 10:36:39 UTC 2017


On Tue, Dec 12, 2017 at 11:50:49AM +0200, Pekka Paalanen wrote:
> On Mon,  4 Dec 2017 15:34:01 +0200
> Alexandros Frantzis <alexandros.frantzis at collabora.com> wrote:
> 
> > Add a helper function to normalize struct timespec values so that the
> > nanoseconds part is less than 1 second and has the same sign as the
> > seconds part (if the seconds part is not 0).
> > 
> > Normalization is required to ensure we can safely convert timespec
> > values to wayland protocol data, i.e, to tv_sec_hi, tv_sec_lo,
> > tv_sec_nsec triplets, and will be used in upcoming commits.
> > 
> > Signed-off-by: Alexandros Frantzis <alexandros.frantzis at collabora.com>
> > ---
> >  shared/timespec-util.h | 28 ++++++++++++++++++++++
> >  tests/timespec-test.c  | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 93 insertions(+)
> > 
> > diff --git a/shared/timespec-util.h b/shared/timespec-util.h
> > index f9736c27..a10edf5b 100644
> > --- a/shared/timespec-util.h
> > +++ b/shared/timespec-util.h
> > @@ -33,6 +33,34 @@
> >  
> >  #define NSEC_PER_SEC 1000000000
> >  
> > +/* Normalize a timespec
> > + *
> > + * \param r[out] normalized timespec
> > + * \param a[in] timespec to normalize
> > + *
> > + * Normalize a timespec so that tv_nsec is less than 1 second
> > + * and has the same sign as tv_sec (if tv_sec is non-zero).
> 
> Hi,

Hi Pekka,

thanks for the review.

> why does it need to have the same sign?
> E.g. timespec_sub() ensures nsec is non-negative, as do the add
> functions.

The goal was to make timespec_normalize more generally useful and
independent of any current behavior. I didn't want to assume that the
provided timespec would be produced necessarily by using the
aforementioned functions that already provide the same-sign guarantee.

> Otherwise this is fine, but I would also have the protocol spec forbid
> non-normalized timespec values like the presentation-timing extension
> does.

That's a good point. I will update the input-timestamps spec wording.

Thanks,
Alexandros


More information about the wayland-devel mailing list