mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:04:43 +01:00
std.Io make Clock.resolution fallible
This commit is contained in:
parent
11476d83c9
commit
fe5da36aa3
2 changed files with 9 additions and 4 deletions
|
|
@ -232,7 +232,7 @@ pub const VTable = struct {
|
|||
progressParentFile: *const fn (?*anyopaque) std.Progress.ParentFileError!File,
|
||||
|
||||
now: *const fn (?*anyopaque, Clock) Timestamp,
|
||||
clockResolution: *const fn (?*anyopaque, Clock) Duration,
|
||||
clockResolution: *const fn (?*anyopaque, Clock) Clock.ResolutionError!Duration,
|
||||
sleep: *const fn (?*anyopaque, Timeout) Cancelable!void,
|
||||
|
||||
random: *const fn (?*anyopaque, buffer: []u8) void,
|
||||
|
|
@ -713,9 +713,14 @@ pub const Clock = enum {
|
|||
return io.vtable.now(io.userdata, clock);
|
||||
}
|
||||
|
||||
pub const ResolutionError = error{
|
||||
ClockUnavailable,
|
||||
Unexpected,
|
||||
};
|
||||
|
||||
/// Reveals the granularity of `clock`. May be zero, indicating
|
||||
/// unsupported clock.
|
||||
pub fn resolution(clock: Clock, io: Io) Io.Duration {
|
||||
pub fn resolution(clock: Clock, io: Io) ResolutionError!Io.Duration {
|
||||
return io.vtable.clockResolution(io.userdata, clock);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10833,7 +10833,7 @@ fn nowInner(clock: Io.Clock) Io.Timestamp {
|
|||
};
|
||||
}
|
||||
|
||||
fn clockResolution(userdata: ?*anyopaque, clock: Io.Clock) Io.Duration {
|
||||
fn clockResolution(userdata: ?*anyopaque, clock: Io.Clock) Io.Clock.ResolutionError!Io.Duration {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
_ = t;
|
||||
return switch (native_os) {
|
||||
|
|
@ -10872,7 +10872,7 @@ fn clockResolution(userdata: ?*anyopaque, clock: Io.Clock) Io.Duration {
|
|||
};
|
||||
}
|
||||
|
||||
fn clockResolutionPosix(clock: Io.Clock) Io.Duration {
|
||||
fn clockResolutionPosix(clock: Io.Clock) Io.Clock.ResolutionError!Io.Duration {
|
||||
const clock_id: posix.clockid_t = clockToPosix(clock);
|
||||
var timespec: posix.timespec = undefined;
|
||||
return switch (posix.errno(posix.system.clock_getres(clock_id, ×pec))) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue