On Wed, 1 Mar 2017 11:34:02 +0000 Daniel Stone <[email protected]> wrote:
> Paralleling timespec_to_nsec, converts to milliseconds. > > Signed-off-by: Daniel Stone <[email protected]> > Reviewed-by: Pekka Paalanen <[email protected]> > --- > 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/libweston/compositor.c b/libweston/compositor.c > index 813f701..a28738e 100644 > --- a/libweston/compositor.c > +++ b/libweston/compositor.c > @@ -2388,7 +2388,7 @@ weston_output_finish_frame(struct weston_output *output, > output->msc, > presented_flags); > > - output->frame_time = stamp->tv_sec * 1000 + stamp->tv_nsec / 1000000; > + output->frame_time = timespec_to_msec(stamp); > > weston_compositor_read_presentation_clock(compositor, &now); > timespec_sub(&gone, &now, stamp); > 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? Thanks, pq > + */ > +static inline int64_t > +timespec_to_msec(const struct timespec *a) > +{ > + return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; > +} > + > /* Convert milli-Hertz to nanoseconds > * > * \param mhz frequency in mHz, not zero > diff --git a/tests/timespec-test.c b/tests/timespec-test.c > index cd3b1c1..712d1ac 100644 > --- a/tests/timespec-test.c > +++ b/tests/timespec-test.c > @@ -60,6 +60,15 @@ ZUC_TEST(timespec_test, timespec_to_nsec) > ZUC_ASSERT_EQ(timespec_to_nsec(&a), (NSEC_PER_SEC * 4ULL) + 4); > } > > +ZUC_TEST(timespec_test, timespec_to_msec) > +{ > + struct timespec a; > + > + a.tv_sec = 4; > + a.tv_nsec = 4000000; > + ZUC_ASSERT_EQ(timespec_to_msec(&a), (4000ULL) + 4); > +} > + > ZUC_TEST(timespec_test, millihz_to_nsec) > { > ZUC_ASSERT_EQ(millihz_to_nsec(60000), 16666666);
pgpRLgDl7qhJn.pgp
Description: OpenPGP digital signature
_______________________________________________ wayland-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/wayland-devel
