authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-03 01:02:48-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-03 01:02:48-08:00
logfe5da36aa3b1dbeb02276c6628640c68a5922191
treed08e96deb3a4630314ab968e1c7fb64b2475de47
parent11476d83c9218ad2b22ab59b2fee3a4a4bf36367

std.Io make Clock.resolution fallible


2 files changed, 9 insertions(+), 4 deletions(-)

lib/std/Io.zig+7-2
......@@ -232,7 +232,7 @@ pub const VTable = struct {
232232 progressParentFile: *const fn (?*anyopaque) std.Progress.ParentFileError!File,
233233
234234 now: *const fn (?*anyopaque, Clock) Timestamp,
235 clockResolution: *const fn (?*anyopaque, Clock) Duration,
235 clockResolution: *const fn (?*anyopaque, Clock) Clock.ResolutionError!Duration,
236236 sleep: *const fn (?*anyopaque, Timeout) Cancelable!void,
237237
238238 random: *const fn (?*anyopaque, buffer: []u8) void,
......@@ -713,9 +713,14 @@ pub const Clock = enum {
713713 return io.vtable.now(io.userdata, clock);
714714 }
715715
716 pub const ResolutionError = error{
717 ClockUnavailable,
718 Unexpected,
719 };
720
716721 /// Reveals the granularity of `clock`. May be zero, indicating
717722 /// unsupported clock.
718 pub fn resolution(clock: Clock, io: Io) Io.Duration {
723 pub fn resolution(clock: Clock, io: Io) ResolutionError!Io.Duration {
719724 return io.vtable.clockResolution(io.userdata, clock);
720725 }
721726
lib/std/Io/Threaded.zig+2-2
......@@ -10833,7 +10833,7 @@ fn nowInner(clock: Io.Clock) Io.Timestamp {
1083310833 };
1083410834}
1083510835
10836fn clockResolution(userdata: ?*anyopaque, clock: Io.Clock) Io.Duration {
10836fn clockResolution(userdata: ?*anyopaque, clock: Io.Clock) Io.Clock.ResolutionError!Io.Duration {
1083710837 const t: *Threaded = @ptrCast(@alignCast(userdata));
1083810838 _ = t;
1083910839 return switch (native_os) {
......@@ -10872,7 +10872,7 @@ fn clockResolution(userdata: ?*anyopaque, clock: Io.Clock) Io.Duration {
1087210872 };
1087310873}
1087410874
10875fn clockResolutionPosix(clock: Io.Clock) Io.Duration {
10875fn clockResolutionPosix(clock: Io.Clock) Io.Clock.ResolutionError!Io.Duration {
1087610876 const clock_id: posix.clockid_t = clockToPosix(clock);
1087710877 var timespec: posix.timespec = undefined;
1087810878 return switch (posix.errno(posix.system.clock_getres(clock_id, &timespec))) {