| author | |
| committer | |
| log | fe5da36aa3b1dbeb02276c6628640c68a5922191 |
| tree | d08e96deb3a4630314ab968e1c7fb64b2475de47 |
| parent | 11476d83c9218ad2b22ab59b2fee3a4a4bf36367 |
2 files changed, 9 insertions(+), 4 deletions(-)
lib/std/Io.zig+7-2| ... | ... | @@ -232,7 +232,7 @@ pub const VTable = struct { |
| 232 | 232 | progressParentFile: *const fn (?*anyopaque) std.Progress.ParentFileError!File, |
| 233 | 233 | |
| 234 | 234 | now: *const fn (?*anyopaque, Clock) Timestamp, |
| 235 | clockResolution: *const fn (?*anyopaque, Clock) Duration, | |
| 235 | clockResolution: *const fn (?*anyopaque, Clock) Clock.ResolutionError!Duration, | |
| 236 | 236 | sleep: *const fn (?*anyopaque, Timeout) Cancelable!void, |
| 237 | 237 | |
| 238 | 238 | random: *const fn (?*anyopaque, buffer: []u8) void, |
| ... | ... | @@ -713,9 +713,14 @@ pub const Clock = enum { |
| 713 | 713 | return io.vtable.now(io.userdata, clock); |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | pub const ResolutionError = error{ | |
| 717 | ClockUnavailable, | |
| 718 | Unexpected, | |
| 719 | }; | |
| 720 | ||
| 716 | 721 | /// Reveals the granularity of `clock`. May be zero, indicating |
| 717 | 722 | /// unsupported clock. |
| 718 | pub fn resolution(clock: Clock, io: Io) Io.Duration { | |
| 723 | pub fn resolution(clock: Clock, io: Io) ResolutionError!Io.Duration { | |
| 719 | 724 | return io.vtable.clockResolution(io.userdata, clock); |
| 720 | 725 | } |
| 721 | 726 |
lib/std/Io/Threaded.zig+2-2| ... | ... | @@ -10833,7 +10833,7 @@ fn nowInner(clock: Io.Clock) Io.Timestamp { |
| 10833 | 10833 | }; |
| 10834 | 10834 | } |
| 10835 | 10835 | |
| 10836 | fn clockResolution(userdata: ?*anyopaque, clock: Io.Clock) Io.Duration { | |
| 10836 | fn clockResolution(userdata: ?*anyopaque, clock: Io.Clock) Io.Clock.ResolutionError!Io.Duration { | |
| 10837 | 10837 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 10838 | 10838 | _ = t; |
| 10839 | 10839 | return switch (native_os) { |
| ... | ... | @@ -10872,7 +10872,7 @@ fn clockResolution(userdata: ?*anyopaque, clock: Io.Clock) Io.Duration { |
| 10872 | 10872 | }; |
| 10873 | 10873 | } |
| 10874 | 10874 | |
| 10875 | fn clockResolutionPosix(clock: Io.Clock) Io.Duration { | |
| 10875 | fn clockResolutionPosix(clock: Io.Clock) Io.Clock.ResolutionError!Io.Duration { | |
| 10876 | 10876 | const clock_id: posix.clockid_t = clockToPosix(clock); |
| 10877 | 10877 | var timespec: posix.timespec = undefined; |
| 10878 | 10878 | return switch (posix.errno(posix.system.clock_getres(clock_id, &timespec))) { |