[PATCH weston v2 03/11] timespec: Add timespec_to_msec helper

Pekka Paalanen ppaalanen at gmail.com
Wed Mar 8 12:27:17 UTC 2017


On Wed, 8 Mar 2017 13:34:18 +0200
Pekka Paalanen <ppaalanen at gmail.com> wrote:

> On Wed,  1 Mar 2017 11:34:02 +0000
> Daniel Stone <daniels at collabora.com> wrote:
> 
> > Paralleling timespec_to_nsec, converts to milliseconds.
> > 
> > Signed-off-by: Daniel Stone <daniels at collabora.com>
> > Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
> > ---
> >  libweston/compositor.c |  2 +-
> >  shared/timespec-util.h | 11 +++++++++++
> >  tests/timespec-test.c  |  9 +++++++++
> >  3 files changed, 21 insertions(+), 1 deletion(-)
> > 
> > v2: No changes.
> > 

> > diff --git a/shared/timespec-util.h b/shared/timespec-util.h
> > index 13948b1..c8e3cd6 100644
> > --- a/shared/timespec-util.h
> > +++ b/shared/timespec-util.h
> > @@ -93,6 +93,17 @@ timespec_to_nsec(const struct timespec *a)
> >  	return (int64_t)a->tv_sec * NSEC_PER_SEC + a->tv_nsec;
> >  }
> >  
> > +/* Convert timespec to milliseconds
> > + *
> > + * \param a timespec
> > + * \return milliseconds  
> 
> Hi,
> 
> might want to note, that this rounds to integer milliseconds towards
> zero. It's not round() nor floor(), it's trunc().
> 
> Shall I just add that note when merging?

> > + */
> > +static inline int64_t
> > +timespec_to_msec(const struct timespec *a)
> > +{
> > +	return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
> > +}

Wait, I'm wrong, aren't I?

The seconds value is always taken as is, nsec value (never negative) is
always truncated towards zero.

timespec { -2, 100 } > -2.0 s but it gets rounded to -2000 ms, i.e.
down. That's not trunc(), that's floor(). Right?


Thanks,
pq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20170308/cba4af9e/attachment.sig>


More information about the wayland-devel mailing list