summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorPekka Paalanen <pekka.paalanen@collabora.co.uk>2015-07-03 15:08:53 +0300
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2015-07-16 13:55:05 +0300
commitd7894d052a8e8944d20e1f751f3275382e48cc12 (patch)
tree98a0c1b0b84669509e1d4aa14c83111e7404466f /shared
parentaa21f6249f746e9d83c59161abd175dd10253221 (diff)
downloadweston-d7894d052a8e8944d20e1f751f3275382e48cc12.tar.gz
compositor,shared: add millihz_to_nsec()
A helper to improbe readability. Cc: Daniel Stone <daniels@collabora.com> Cc: Mario Kleiner <mario.kleiner.de@gmail.com> Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'shared')
-rw-r--r--shared/timespec-util.h14
1 files changed, 14 insertions, 0 deletions
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 <stdint.h>
+#include <assert.h>
+
#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 */