From 94cd1908dbf957e6ea4b4e152065181a74161a98 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Fri, 22 Mar 2019 10:57:18 -0500 Subject: [PATCH] aux/util: Add time_ns_to_s and time_s_to_ns --- src/xrt/auxiliary/util/u_time.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/xrt/auxiliary/util/u_time.h b/src/xrt/auxiliary/util/u_time.h index bc284eae3..10f7230fc 100644 --- a/src/xrt/auxiliary/util/u_time.h +++ b/src/xrt/auxiliary/util/u_time.h @@ -22,9 +22,42 @@ extern "C" { * Integer timestamp type. * * @see time_state + * @see time_duration_ns */ typedef int64_t timepoint_ns; +/*! + * Integer duration type in nanoseconds. + * + * Logical type of timepoint differences. + * + * @see time_state + * @see timepoint_ns + */ +typedef int64_t time_duration_ns; + +/*! + * Convert nanoseconds duration to float seconds. + * + * @see timepoint_ns + */ +static inline float +time_ns_to_s(time_duration_ns ns) +{ + return (float)(ns) / 1000000000.0f; +} + +/*! + * Convert float seconds to nanoseconds. + * + * @see timepoint_ns + */ +static inline time_duration_ns +time_s_to_ns(float duration) +{ + return (time_duration_ns)(duration * 1000000000.0f); +} + /*! * @struct time_state util/u_time.h * @brief Time-keeping state structure.