From d7894d052a8e8944d20e1f751f3275382e48cc12 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Fri, 3 Jul 2015 15:08:53 +0300 Subject: [PATCH] compositor,shared: add millihz_to_nsec() A helper to improbe readability. Cc: Daniel Stone Cc: Mario Kleiner Signed-off-by: Pekka Paalanen --- shared/timespec-util.h | 14 ++++++++++++++ src/compositor.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/shared/timespec-util.h b/shared/timespec-util.h index 0e05efc7..edd4ec14 100644 --- a/shared/timespec-util.h +++ b/shared/timespec-util.h @@ -26,6 +26,9 @@ #ifndef TIMESPEC_UTIL_H #define TIMESPEC_UTIL_H +#include +#include + #define NSEC_PER_SEC 1000000000 /* Subtract timespecs @@ -57,5 +60,16 @@ timespec_to_nsec(const struct timespec *a) return (int64_t)a->tv_sec * NSEC_PER_SEC + a->tv_nsec; } +/* Convert milli-Hertz to nanoseconds + * + * \param mhz frequency in mHz, not zero + * \return period in nanoseconds + */ +static inline int64_t +millihz_to_nsec(uint32_t mhz) +{ + assert(mhz > 0); + return 1000000000000LL / mhz; +} #endif /* TIMESPEC_UTIL_H */ diff --git a/src/compositor.c b/src/compositor.c index cafac296..ea507e8c 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -2349,7 +2349,7 @@ weston_output_finish_frame(struct weston_output *output, TL_POINT("core_repaint_finished", TLP_OUTPUT(output), TLP_VBLANK(stamp), TLP_END); - refresh_nsec = 1000000000000LL / output->current_mode->refresh; + refresh_nsec = millihz_to_nsec(output->current_mode->refresh); weston_presentation_feedback_present_list(&output->feedback_list, output, refresh_nsec, stamp, output->msc,