diff options
author | Derek Foreman <derek.foreman@collabora.com> | 2022-10-25 14:54:58 -0500 |
---|---|---|
committer | Pekka Paalanen <pq@iki.fi> | 2022-10-27 08:13:30 +0000 |
commit | 5079f0b2f925a19d514340c1943d3c6b5f33514b (patch) | |
tree | 31b03f99e6f36a10e015654c782107123c95a94a /shared | |
parent | 2ca2eac39a3b7ec850866bf155362a01e997a195 (diff) | |
download | weston-5079f0b2f925a19d514340c1943d3c6b5f33514b.tar.gz |
helpers: Add a u64 from 2 u32 helper
We do this enough that having a single implementation for it is probably
a win.
Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
Diffstat (limited to 'shared')
-rw-r--r-- | shared/helpers.h | 8 | ||||
-rw-r--r-- | shared/timespec-util.h | 3 |
2 files changed, 10 insertions, 1 deletions
diff --git a/shared/helpers.h b/shared/helpers.h index 7b722096..32938eca 100644 --- a/shared/helpers.h +++ b/shared/helpers.h @@ -22,6 +22,8 @@ #ifndef WESTON_HELPERS_H #define WESTON_HELPERS_H +#include <stdint.h> + #ifdef __cplusplus extern "C" { #endif @@ -171,6 +173,12 @@ do { \ */ #define WESTON_EXPORT_FOR_TESTS __attribute__ ((visibility("default"))) +static inline uint64_t +u64_from_u32s(uint32_t hi, uint32_t lo) +{ + return ((uint64_t)hi << 32) + lo; +} + #ifdef __cplusplus } #endif diff --git a/shared/timespec-util.h b/shared/timespec-util.h index f79969bb..f76b9537 100644 --- a/shared/timespec-util.h +++ b/shared/timespec-util.h @@ -30,6 +30,7 @@ #include <assert.h> #include <time.h> #include <stdbool.h> +#include <shared/helpers.h> #define NSEC_PER_SEC 1000000000 @@ -216,7 +217,7 @@ static inline void timespec_from_proto(struct timespec *a, uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec) { - a->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo; + a->tv_sec = u64_from_u32s(tv_sec_hi, tv_sec_lo); a->tv_nsec = tv_nsec; } |