Fixed compiler errors around darwin code.
This commit is contained in:
parent
8b66dd8c7d
commit
bf9cf28322
@ -4,7 +4,7 @@ pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) c_int;
|
|||||||
pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: &u8, buf_len: usize, basep: &i64) usize;
|
pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: &u8, buf_len: usize, basep: &i64) usize;
|
||||||
|
|
||||||
pub extern "c" fn mach_absolute_time() u64;
|
pub extern "c" fn mach_absolute_time() u64;
|
||||||
pub extern "c" fn mach_timebase_info(&mach_timebase_info_data) void;
|
pub extern "c" fn mach_timebase_info(tinfo: ?&mach_timebase_info_data) void;
|
||||||
|
|
||||||
pub use @import("../os/darwin_errno.zig");
|
pub use @import("../os/darwin_errno.zig");
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int;
|
|||||||
pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize;
|
pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize;
|
||||||
pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8;
|
pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8;
|
||||||
pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int;
|
pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int;
|
||||||
pub extern "c" fn gettimeofday(&timeval, ?&timezone) c_int;
|
pub extern "c" fn gettimeofday(tv: ?&timeval, tz: ?&timezone) c_int;
|
||||||
pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int;
|
pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int;
|
||||||
pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?×pec) c_int;
|
pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?×pec) c_int;
|
||||||
pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
|
pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
|
||||||
|
@ -251,8 +251,8 @@ pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) u
|
|||||||
return errnoWrap(c.readlink(path, buf_ptr, buf_len));
|
return errnoWrap(c.readlink(path, buf_ptr, buf_len));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gettimeofday(&timeval, ?&timezone) usize {
|
pub fn gettimeofday(tv: ?&timeval, tz: ?&timezone) usize {
|
||||||
return errnoWrap(c.gettimeofday(timeval, timezone));
|
return errnoWrap(c.gettimeofday(tv, tz));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nanosleep(req: &const timespec, rem: ?×pec) usize {
|
pub fn nanosleep(req: &const timespec, rem: ?×pec) usize {
|
||||||
@ -322,3 +322,11 @@ pub fn sigaddset(set: &sigset_t, signo: u5) void {
|
|||||||
fn errnoWrap(value: isize) usize {
|
fn errnoWrap(value: isize) usize {
|
||||||
return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value);
|
return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub const timezone = c.timezone;
|
||||||
|
pub const timeval = c.timeval;
|
||||||
|
pub const mach_timebase_info_data = c.mach_timebase_info_data;
|
||||||
|
|
||||||
|
pub const mach_absolute_time = c.mach_absolute_time;
|
||||||
|
pub const mach_timebase_info = c.mach_timebase_info;
|
@ -79,8 +79,9 @@ fn miliTimestampDarwin() u64 {
|
|||||||
var tv: darwin.timeval = undefined;
|
var tv: darwin.timeval = undefined;
|
||||||
var err = darwin.gettimeofday(&tv, null);
|
var err = darwin.gettimeofday(&tv, null);
|
||||||
debug.assert(err == 0);
|
debug.assert(err == 0);
|
||||||
return tv.tv_sec * ms_per_s + ts.tv_usec
|
const sec_ms = tv.tv_sec * ms_per_s;
|
||||||
* (us_per_s / ms_per_s);
|
const usec_ms = @divFloor(tv.tv_usec, (us_per_s / ms_per_s));
|
||||||
|
return u64(sec_ms) + u64(usec_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn miliTimestampPosix() u64 {
|
fn miliTimestampPosix() u64 {
|
||||||
@ -136,7 +137,8 @@ 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.
|
||||||
pub fn start() !Timer {
|
const TimerError = error{TimerUnsupported};
|
||||||
|
pub fn start() TimerError!Timer {
|
||||||
var self: Timer = undefined;
|
var self: Timer = undefined;
|
||||||
|
|
||||||
switch(builtin.os) {
|
switch(builtin.os) {
|
||||||
@ -163,9 +165,9 @@ pub const Timer = struct {
|
|||||||
self.start_time = u64(ts.tv_sec * ns_per_s + ts.tv_nsec);
|
self.start_time = u64(ts.tv_sec * ns_per_s + ts.tv_nsec);
|
||||||
},
|
},
|
||||||
Os.macosx, Os.ios => {
|
Os.macosx, Os.ios => {
|
||||||
darwin.c.mach_timebase_info(&self.frequency);
|
darwin.mach_timebase_info(&self.frequency);
|
||||||
self.resolution = @divFloor(self.frequency.numer, self.denom);
|
self.resolution = @divFloor(self.frequency.numer, self.frequency.denom);
|
||||||
self.start_time = darwin.c.mach_absolute_time();
|
self.start_time = darwin.mach_absolute_time();
|
||||||
},
|
},
|
||||||
else => @compileError("Unsupported OS"),
|
else => @compileError("Unsupported OS"),
|
||||||
}
|
}
|
||||||
@ -213,9 +215,7 @@ pub const Timer = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clockDarwin() u64 {
|
fn clockDarwin() u64 {
|
||||||
var result: u64 = undefined;
|
return darwin.mach_absolute_time();
|
||||||
darwin.c.mach_absolute_time(&result);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clockLinux() u64 {
|
fn clockLinux() u64 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user