aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Wick <sebastian.wick@redhat.com>2024-02-07 18:53:16 +0100
committerDerek Foreman <derek.foreman@collabora.com>2025-02-04 14:09:51 +0000
commit893e4fc46d31d1cc51c1e39481f5659a40152233 (patch)
tree89f8ae7a67c3557225d672c4124dcad3f75d6bfb
parenttimespec: Pull in timespec_after and timespec_add from mesa (diff)
downloadwayland-893e4fc46d31d1cc51c1e39481f5659a40152233.tar
wayland-893e4fc46d31d1cc51c1e39481f5659a40152233.tar.gz
wayland-893e4fc46d31d1cc51c1e39481f5659a40152233.tar.bz2
wayland-893e4fc46d31d1cc51c1e39481f5659a40152233.tar.lz
wayland-893e4fc46d31d1cc51c1e39481f5659a40152233.tar.xz
wayland-893e4fc46d31d1cc51c1e39481f5659a40152233.tar.zst
wayland-893e4fc46d31d1cc51c1e39481f5659a40152233.zip
timespec: Implement saturating timespec substraction
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
-rw-r--r--src/timespec-util.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/timespec-util.h b/src/timespec-util.h
index d37568d..d3c53bd 100644
--- a/src/timespec-util.h
+++ b/src/timespec-util.h
@@ -290,4 +290,22 @@ timespec_add(struct timespec *r,
}
}
+/**
+ * Saturating timespec subtraction
+ *
+ * \param r[out] result: max(a - b, 0)
+ * \param a[in] operand
+ * \param b[in] operand
+ */
+static inline void
+timespec_sub_saturate(struct timespec *r,
+ const struct timespec *a, const struct timespec *b)
+{
+ timespec_sub(r, a, b);
+ if (r->tv_sec < 0) {
+ r->tv_sec = 0;
+ r->tv_nsec = 0;
+ }
+}
+
#endif /* TIMESPEC_UTIL_H */