mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-29 05:40:16 -04:00
timespec: Implement saturating timespec substraction
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
This commit is contained in:
parent
9d5de6062b
commit
893e4fc46d
1 changed files with 18 additions and 0 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue