diff options
| author | Sebastian Wick <sebastian.wick@redhat.com> | 2024-02-07 18:51:39 +0100 |
|---|---|---|
| committer | Derek Foreman <derek.foreman@collabora.com> | 2025-02-04 14:09:51 +0000 |
| commit | 9d5de6062ba82a56d25d8a53ccace3afecbf50e5 (patch) | |
| tree | 1c9060ebf919b1b2a5979626fd4b1280a9255c0f /src | |
| parent | timespec: Pull in timespec.h from weston (diff) | |
| download | wayland-9d5de6062ba82a56d25d8a53ccace3afecbf50e5.tar wayland-9d5de6062ba82a56d25d8a53ccace3afecbf50e5.tar.gz wayland-9d5de6062ba82a56d25d8a53ccace3afecbf50e5.tar.bz2 wayland-9d5de6062ba82a56d25d8a53ccace3afecbf50e5.tar.lz wayland-9d5de6062ba82a56d25d8a53ccace3afecbf50e5.tar.xz wayland-9d5de6062ba82a56d25d8a53ccace3afecbf50e5.tar.zst wayland-9d5de6062ba82a56d25d8a53ccace3afecbf50e5.zip | |
timespec: Pull in timespec_after and timespec_add from mesa
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/timespec-util.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/timespec-util.h b/src/timespec-util.h index f79969b..d37568d 100644 --- a/src/timespec-util.h +++ b/src/timespec-util.h @@ -256,4 +256,38 @@ millihz_to_nsec(uint32_t mhz) return 1000000000000LL / mhz; } +/** + * Checks whether a timespec value is after another + * + * \param a[in] timespec to compare + * \param b[in] timespec to compare + * \return whether a is after b + */ +static inline bool +timespec_after(const struct timespec *a, const struct timespec *b) +{ + return (a->tv_sec == b->tv_sec) ? + (a->tv_nsec > b->tv_nsec) : + (a->tv_sec > b->tv_sec); +} + +/** + * Add timespecs + * + * \param r[out] result: a + b + * \param a[in] operand + * \param b[in] operand + */ +static inline void +timespec_add(struct timespec *r, + const struct timespec *a, const struct timespec *b) +{ + r->tv_sec = a->tv_sec + b->tv_sec; + r->tv_nsec = a->tv_nsec + b->tv_nsec; + if (r->tv_nsec > NSEC_PER_SEC) { + r->tv_sec++; + r->tv_nsec -= NSEC_PER_SEC; + } +} + #endif /* TIMESPEC_UTIL_H */ |
