Skip to content

Commit

Permalink
clock: Fix current monotonic time in millis u32 overflow panic
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Jan 24, 2025
1 parent 2ae322b commit 02de152
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ impl Time<Monotonic> {
/// This should match timestamps from libinput:
/// <https://wayland.freedesktop.org/libinput/doc/latest/timestamps.html>
pub fn as_millis(&self) -> u32 {
// Assume monotonic clock (but not realitime) fits as milliseconds in 32-bit
debug_assert!(self.tp.tv_sec >= 0);
debug_assert!(self.tp.tv_nsec >= 0);
self.tp.tv_sec as u32 * 1000 + self.tp.tv_nsec as u32 / 1000000

// The monotonic clock does not fit as milliseconds in 32-bit after ~50 days of uptime. We
// do a modulo conversion which should match what happens in libinput.
(self.as_micros() / 1000) as u32
}

/// Returns the time in microseconds
Expand Down

0 comments on commit 02de152

Please sign in to comment.