Skip to content

Commit

Permalink
river: wrap monotonic time > 2^32-1 milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
ifreund committed Dec 30, 2024
1 parent ab879e2 commit 6abcc68
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions river/Cursor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,13 @@ pub fn updateState(cursor: *Cursor) void {
if (!cursor.hidden) {
var now: posix.timespec = undefined;
posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
const msec: u32 = @intCast(now.tv_sec * std.time.ms_per_s +
@divTrunc(now.tv_nsec, std.time.ns_per_ms));
// 2^32-1 milliseconds is ~50 days, which is a realistic uptime.
// This means that we must wrap if the monotonic time is greater than
// 2^32-1 milliseconds and hope that clients don't get too confused.
const msec: u32 = @intCast(@rem(
now.tv_sec *% std.time.ms_per_s +% @divTrunc(now.tv_nsec, std.time.ns_per_ms),
math.maxInt(u32),
));
cursor.passthrough(msec);
}
},
Expand Down

0 comments on commit 6abcc68

Please sign in to comment.