util: add a bunch more time conversions
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 21 Oct 2024 01:07:34 +0000 (11:07 +1000)
committerMarge Bot <emma+marge@anholt.net>
Wed, 30 Oct 2024 23:20:42 +0000 (23:20 +0000)
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1067>

src/util-time.h

index e534fceada30aceb343bc9d55f17cee110beb88c..4600dc59b35fc4839535f9ecd2cf99dda9bd6437 100644 (file)
@@ -58,6 +58,12 @@ ms2us(uint64_t ms)
        return us(ms * 1000);
 }
 
+static inline uint32_t
+ms2s(uint64_t ms)
+{
+       return ms / 1000;
+}
+
 static inline uint64_t
 s2us(uint64_t s)
 {
@@ -76,6 +82,12 @@ us2ms(uint64_t us)
        return (uint32_t)(us / 1000);
 }
 
+static inline uint32_t
+us2s(uint64_t us)
+{
+       return ms2s(us2ms(us));
+}
+
 static inline double
 us2ms_f(uint64_t us)
 {
@@ -88,6 +100,12 @@ tv2us(const struct timeval *tv)
        return s2us(tv->tv_sec) + tv->tv_usec;
 }
 
+static inline uint64_t
+tp2us(const struct timespec *tp)
+{
+       return s2us(tp->tv_sec) + ns2us(tp->tv_nsec);
+}
+
 static inline struct timeval
 us2tv(uint64_t time)
 {