shared: Add timespec_to_proto helper function
Add helper function to convert from struct timespec values to tv_sec_hi, tv_sec_lo, tv_nsec triplets used for sending high-resolution timestamp data over the wayland protocol. Replace existing conversion code with the helper function. Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
committed by
Pekka Paalanen
parent
787fa611de
commit
10d708d268
@@ -147,6 +147,30 @@ timespec_to_usec(const struct timespec *a)
|
||||
return (int64_t)a->tv_sec * 1000000 + a->tv_nsec / 1000;
|
||||
}
|
||||
|
||||
/* Convert timespec to protocol data
|
||||
*
|
||||
* \param a timespec
|
||||
* \param tv_sec_hi[out] the high bytes of the seconds part
|
||||
* \param tv_sec_lo[out] the low bytes of the seconds part
|
||||
* \param tv_nsec[out] the nanoseconds part
|
||||
*
|
||||
* The input timespec must be normalized (the nanoseconds part should
|
||||
* be less than 1 second) and non-negative.
|
||||
*/
|
||||
static inline void
|
||||
timespec_to_proto(const struct timespec *a, uint32_t *tv_sec_hi,
|
||||
uint32_t *tv_sec_lo, uint32_t *tv_nsec)
|
||||
{
|
||||
assert(a->tv_sec >= 0);
|
||||
assert(a->tv_nsec >= 0 && a->tv_nsec < NSEC_PER_SEC);
|
||||
|
||||
uint64_t sec64 = a->tv_sec;
|
||||
|
||||
*tv_sec_hi = sec64 >> 32;
|
||||
*tv_sec_lo = sec64 & 0xffffffff;
|
||||
*tv_nsec = a->tv_nsec;
|
||||
}
|
||||
|
||||
/* Convert nanoseconds to timespec
|
||||
*
|
||||
* \param a timespec
|
||||
|
||||
Reference in New Issue
Block a user