Use std.os.errorUnexpectedPosix if timer initialization encounters unexpected error
This commit is contained in:
parent
89eade0548
commit
ca4053ba49
@ -152,7 +152,7 @@ pub const Timer = struct {
|
|||||||
// impossible here barring cosmic rays or other such occurances of
|
// impossible here barring cosmic rays or other such occurances of
|
||||||
// incredibly bad luck.
|
// incredibly bad luck.
|
||||||
//On Darwin: This cannot fail, as far as I am able to tell.
|
//On Darwin: This cannot fail, as far as I am able to tell.
|
||||||
const TimerError = error{TimerUnsupported, UnexpectedErrnoValue};
|
const TimerError = error{TimerUnsupported, Unexpected};
|
||||||
pub fn start() TimerError!Timer {
|
pub fn start() TimerError!Timer {
|
||||||
var self: Timer = undefined;
|
var self: Timer = undefined;
|
||||||
|
|
||||||
@ -177,14 +177,17 @@ pub const Timer = struct {
|
|||||||
// seccomp is going to block us it will at least do so consistently
|
// seccomp is going to block us it will at least do so consistently
|
||||||
var ts: posix.timespec = undefined;
|
var ts: posix.timespec = undefined;
|
||||||
var result = posix.clock_getres(monotonic_clock_id, &ts);
|
var result = posix.clock_getres(monotonic_clock_id, &ts);
|
||||||
switch (posix.getErrno(result)) {
|
var errno = posix.getErrno(result);
|
||||||
|
switch (errno) {
|
||||||
0 => {},
|
0 => {},
|
||||||
posix.EINVAL => return error.TimerUnsupported,
|
posix.EINVAL => return error.TimerUnsupported,
|
||||||
else => return error.UnexpectedErrnoValue,
|
else => return std.os.unexpectedErrorPosix(errno),
|
||||||
}
|
}
|
||||||
self.resolution = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);
|
self.resolution = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);
|
||||||
|
|
||||||
result = posix.clock_gettime(monotonic_clock_id, &ts);
|
result = posix.clock_gettime(monotonic_clock_id, &ts);
|
||||||
if (posix.getErrno(result) != 0) return error.UnexpectedErrnoValue;
|
errno = posix.getErrno(result);
|
||||||
|
if (errno != 0) return std.os.unexpectedErrorPosix(errno);
|
||||||
self.start_time = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);
|
self.start_time = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);
|
||||||
},
|
},
|
||||||
Os.macosx, Os.ios => {
|
Os.macosx, Os.ios => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user