authorgravatar for i@mgxm.meMarcio Giaxa <i@mgxm.me> 2019-01-04 14:42:45-02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-04 16:31:57-05:00
log4d9547ff2e9377abeb87b53e30580cf1a561f9ce
tree5cfe9cc4c51e64b975b2bc6fbe0c510877c715ef
parent1e781a30f63acc597129a8f0c4fee7390a96192b

freebsd: implement clock related functions

- clock_gettime - clock_getres

3 files changed, 14 insertions(+), 4 deletions(-)

std/c/freebsd.zig+2
......@@ -22,6 +22,8 @@ pub extern "c" fn openat(fd: c_int, path: ?[*]const u8, flags: c_int) c_int;
2222pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;
2323pub extern "c" fn setuid(uid: c_uint) c_int;
2424pub extern "c" fn kill(pid: c_int, sig: c_int) c_int;
25pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
26pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
2527
2628/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
2729pub const Kevent = extern struct {
std/os/freebsd/index.zig+8
......@@ -714,6 +714,14 @@ pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
714714 return errnoWrap(c.nanosleep(req, rem));
715715}
716716
717pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
718 return errnoWrap(c.clock_gettime(clk_id, tp));
719}
720
721pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
722 return clock_gettime(clk_id, tp);
723}
724
717725pub fn setuid(uid: u32) usize {
718726 return errnoWrap(c.setuid(uid));
719727}
std/os/time.zig+4-4
......@@ -61,7 +61,7 @@ pub fn timestamp() u64 {
6161/// Get the posix timestamp, UTC, in milliseconds
6262pub const milliTimestamp = switch (builtin.os) {
6363 Os.windows => milliTimestampWindows,
64 Os.linux => milliTimestampPosix,
64 Os.linux, Os.freebsd => milliTimestampPosix,
6565 Os.macosx, Os.ios => milliTimestampDarwin,
6666 else => @compileError("Unsupported OS"),
6767};
......@@ -179,7 +179,7 @@ pub const Timer = struct {
179179 debug.assert(err != windows.FALSE);
180180 self.start_time = @intCast(u64, start_time);
181181 },
182 Os.linux => {
182 Os.linux, Os.freebsd => {
183183 //On Linux, seccomp can do arbitrary things to our ability to call
184184 // syscalls, including return any errno value it wants and
185185 // inconsistently throwing errors. Since we can't account for
......@@ -215,7 +215,7 @@ pub const Timer = struct {
215215 var clock = clockNative() - self.start_time;
216216 return switch (builtin.os) {
217217 Os.windows => @divFloor(clock * ns_per_s, self.frequency),
218 Os.linux => clock,
218 Os.linux, Os.freebsd => clock,
219219 Os.macosx, Os.ios => @divFloor(clock * self.frequency.numer, self.frequency.denom),
220220 else => @compileError("Unsupported OS"),
221221 };
......@@ -236,7 +236,7 @@ pub const Timer = struct {
236236
237237 const clockNative = switch (builtin.os) {
238238 Os.windows => clockWindows,
239 Os.linux => clockLinux,
239 Os.linux, Os.freebsd => clockLinux,
240240 Os.macosx, Os.ios => clockDarwin,
241241 else => @compileError("Unsupported OS"),
242242 };