authorgravatar for tgschultz@gmail.comtgschultz <tgschultz@gmail.com> 2018-04-19 14:53:58-05:00
committergravatar for tgschultz@gmail.comtgschultz <tgschultz@gmail.com> 2018-04-19 14:53:58-05:00
logca4053ba49d8bd171e592783c6024795c4794fda
treed368f3a35e41a2505cc8341286a2f7d0bba00a92
parent89eade0548c3afe8531fcbccc753c5c1e22f8e89

Use std.os.errorUnexpectedPosix if timer initialization encounters unexpected error


1 files changed, 7 insertions(+), 4 deletions(-)

std/os/time.zig+7-4
......@@ -152,7 +152,7 @@ pub const Timer = struct {
152152 // impossible here barring cosmic rays or other such occurances of
153153 // incredibly bad luck.
154154 //On Darwin: This cannot fail, as far as I am able to tell.
155 const TimerError = error{TimerUnsupported, UnexpectedErrnoValue};
155 const TimerError = error{TimerUnsupported, Unexpected};
156156 pub fn start() TimerError!Timer {
157157 var self: Timer = undefined;
158158
......@@ -177,14 +177,17 @@ pub const Timer = struct {
177177 // seccomp is going to block us it will at least do so consistently
178178 var ts: posix.timespec = undefined;
179179 var result = posix.clock_getres(monotonic_clock_id, &ts);
180 switch (posix.getErrno(result)) {
180 var errno = posix.getErrno(result);
181 switch (errno) {
181182 0 => {},
182183 posix.EINVAL => return error.TimerUnsupported,
183 else => return error.UnexpectedErrnoValue,
184 else => return std.os.unexpectedErrorPosix(errno),
184185 }
185186 self.resolution = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);
187
186188 result = posix.clock_gettime(monotonic_clock_id, &ts);
187 if (posix.getErrno(result) != 0) return error.UnexpectedErrnoValue;
189 errno = posix.getErrno(result);
190 if (errno != 0) return std.os.unexpectedErrorPosix(errno);
188191 self.start_time = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);
189192 },
190193 Os.macosx, Os.ios => {