| author | |
| committer | |
| log | bf9cf28322bf19aef72cbc5876e2ca083f762d7c |
| tree | d80b14afe0c211b2620e3cfe6da424fc8bff29ff |
| parent | 8b66dd8c7d2809c3ec86f1eec8acc0a1c184c8c2 |
4 files changed, 21 insertions(+), 13 deletions(-)
std/c/darwin.zig+1-1| ... | ... | @@ -4,7 +4,7 @@ pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) c_int; |
| 4 | 4 | pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: &u8, buf_len: usize, basep: &i64) usize; |
| 5 | 5 | |
| 6 | 6 | pub extern "c" fn mach_absolute_time() u64; |
| 7 | pub extern "c" fn mach_timebase_info(&mach_timebase_info_data) void; | |
| 7 | pub extern "c" fn mach_timebase_info(tinfo: ?&mach_timebase_info_data) void; | |
| 8 | 8 | |
| 9 | 9 | pub use @import("../os/darwin_errno.zig"); |
| 10 | 10 |
std/c/index.zig+1-1| ... | ... | @@ -40,7 +40,7 @@ pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int; |
| 40 | 40 | pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize; |
| 41 | 41 | pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8; |
| 42 | 42 | pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int; |
| 43 | pub extern "c" fn gettimeofday(&timeval, ?&timezone) c_int; | |
| 43 | pub extern "c" fn gettimeofday(tv: ?&timeval, tz: ?&timezone) c_int; | |
| 44 | 44 | pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int; |
| 45 | 45 | pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) c_int; |
| 46 | 46 | pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int; |
std/os/darwin.zig+10-2| ... | ... | @@ -251,8 +251,8 @@ pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) u |
| 251 | 251 | return errnoWrap(c.readlink(path, buf_ptr, buf_len)); |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | pub fn gettimeofday(&timeval, ?&timezone) usize { | |
| 255 | return errnoWrap(c.gettimeofday(timeval, timezone)); | |
| 254 | pub fn gettimeofday(tv: ?&timeval, tz: ?&timezone) usize { | |
| 255 | return errnoWrap(c.gettimeofday(tv, tz)); | |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize { |
| ... | ... | @@ -322,3 +322,11 @@ pub fn sigaddset(set: &sigset_t, signo: u5) void { |
| 322 | 322 | fn errnoWrap(value: isize) usize { |
| 323 | 323 | return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value); |
| 324 | 324 | } |
| 325 | ||
| 326 | ||
| 327 | pub const timezone = c.timezone; | |
| 328 | pub const timeval = c.timeval; | |
| 329 | pub const mach_timebase_info_data = c.mach_timebase_info_data; | |
| 330 | ||
| 331 | pub const mach_absolute_time = c.mach_absolute_time; | |
| 332 | pub const mach_timebase_info = c.mach_timebase_info; | |
| \ No newline at end of file |
std/os/time.zig+9-9| ... | ... | @@ -79,8 +79,9 @@ fn miliTimestampDarwin() u64 { |
| 79 | 79 | var tv: darwin.timeval = undefined; |
| 80 | 80 | var err = darwin.gettimeofday(&tv, null); |
| 81 | 81 | debug.assert(err == 0); |
| 82 | return tv.tv_sec * ms_per_s + ts.tv_usec | |
| 83 | * (us_per_s / ms_per_s); | |
| 82 | const sec_ms = tv.tv_sec * ms_per_s; | |
| 83 | const usec_ms = @divFloor(tv.tv_usec, (us_per_s / ms_per_s)); | |
| 84 | return u64(sec_ms) + u64(usec_ms); | |
| 84 | 85 | } |
| 85 | 86 | |
| 86 | 87 | fn miliTimestampPosix() u64 { |
| ... | ... | @@ -136,7 +137,8 @@ pub const Timer = struct { |
| 136 | 137 | // impossible here barring cosmic rays or other such occurances of |
| 137 | 138 | // incredibly bad luck. |
| 138 | 139 | //On Darwin: This cannot fail, as far as I am able to tell. |
| 139 | pub fn start() !Timer { | |
| 140 | const TimerError = error{TimerUnsupported}; | |
| 141 | pub fn start() TimerError!Timer { | |
| 140 | 142 | var self: Timer = undefined; |
| 141 | 143 | |
| 142 | 144 | switch(builtin.os) { |
| ... | ... | @@ -163,9 +165,9 @@ pub const Timer = struct { |
| 163 | 165 | self.start_time = u64(ts.tv_sec * ns_per_s + ts.tv_nsec); |
| 164 | 166 | }, |
| 165 | 167 | Os.macosx, Os.ios => { |
| 166 | darwin.c.mach_timebase_info(&self.frequency); | |
| 167 | self.resolution = @divFloor(self.frequency.numer, self.denom); | |
| 168 | self.start_time = darwin.c.mach_absolute_time(); | |
| 168 | darwin.mach_timebase_info(&self.frequency); | |
| 169 | self.resolution = @divFloor(self.frequency.numer, self.frequency.denom); | |
| 170 | self.start_time = darwin.mach_absolute_time(); | |
| 169 | 171 | }, |
| 170 | 172 | else => @compileError("Unsupported OS"), |
| 171 | 173 | } |
| ... | ... | @@ -213,9 +215,7 @@ pub const Timer = struct { |
| 213 | 215 | } |
| 214 | 216 | |
| 215 | 217 | fn clockDarwin() u64 { |
| 216 | var result: u64 = undefined; | |
| 217 | darwin.c.mach_absolute_time(&result); | |
| 218 | return result; | |
| 218 | return darwin.mach_absolute_time(); | |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | fn clockLinux() u64 { |