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;...@@ -22,6 +22,8 @@ pub extern "c" fn openat(fd: c_int, path: ?[*]const u8, flags: c_int) c_int;
22pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;22pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;
23pub extern "c" fn setuid(uid: c_uint) c_int;23pub extern "c" fn setuid(uid: c_uint) c_int;
24pub extern "c" fn kill(pid: c_int, sig: c_int) c_int;24pub 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
26/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.28/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
27pub const Kevent = extern struct {29pub const Kevent = extern struct {
std/os/freebsd/index.zig+8
...@@ -714,6 +714,14 @@ pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {...@@ -714,6 +714,14 @@ pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
714 return errnoWrap(c.nanosleep(req, rem));714 return errnoWrap(c.nanosleep(req, rem));
715}715}
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
717pub fn setuid(uid: u32) usize {725pub fn setuid(uid: u32) usize {
718 return errnoWrap(c.setuid(uid));726 return errnoWrap(c.setuid(uid));
719}727}
std/os/time.zig+4-4
...@@ -61,7 +61,7 @@ pub fn timestamp() u64 {...@@ -61,7 +61,7 @@ pub fn timestamp() u64 {
61/// Get the posix timestamp, UTC, in milliseconds61/// Get the posix timestamp, UTC, in milliseconds
62pub const milliTimestamp = switch (builtin.os) {62pub const milliTimestamp = switch (builtin.os) {
63 Os.windows => milliTimestampWindows,63 Os.windows => milliTimestampWindows,
64 Os.linux => milliTimestampPosix,64 Os.linux, Os.freebsd => milliTimestampPosix,
65 Os.macosx, Os.ios => milliTimestampDarwin,65 Os.macosx, Os.ios => milliTimestampDarwin,
66 else => @compileError("Unsupported OS"),66 else => @compileError("Unsupported OS"),
67};67};
...@@ -179,7 +179,7 @@ pub const Timer = struct {...@@ -179,7 +179,7 @@ pub const Timer = struct {
179 debug.assert(err != windows.FALSE);179 debug.assert(err != windows.FALSE);
180 self.start_time = @intCast(u64, start_time);180 self.start_time = @intCast(u64, start_time);
181 },181 },
182 Os.linux => {182 Os.linux, Os.freebsd => {
183 //On Linux, seccomp can do arbitrary things to our ability to call183 //On Linux, seccomp can do arbitrary things to our ability to call
184 // syscalls, including return any errno value it wants and184 // syscalls, including return any errno value it wants and
185 // inconsistently throwing errors. Since we can't account for185 // inconsistently throwing errors. Since we can't account for
...@@ -215,7 +215,7 @@ pub const Timer = struct {...@@ -215,7 +215,7 @@ pub const Timer = struct {
215 var clock = clockNative() - self.start_time;215 var clock = clockNative() - self.start_time;
216 return switch (builtin.os) {216 return switch (builtin.os) {
217 Os.windows => @divFloor(clock * ns_per_s, self.frequency),217 Os.windows => @divFloor(clock * ns_per_s, self.frequency),
218 Os.linux => clock,218 Os.linux, Os.freebsd => clock,
219 Os.macosx, Os.ios => @divFloor(clock * self.frequency.numer, self.frequency.denom),219 Os.macosx, Os.ios => @divFloor(clock * self.frequency.numer, self.frequency.denom),
220 else => @compileError("Unsupported OS"),220 else => @compileError("Unsupported OS"),
221 };221 };
...@@ -236,7 +236,7 @@ pub const Timer = struct {...@@ -236,7 +236,7 @@ pub const Timer = struct {
236236
237 const clockNative = switch (builtin.os) {237 const clockNative = switch (builtin.os) {
238 Os.windows => clockWindows,238 Os.windows => clockWindows,
239 Os.linux => clockLinux,239 Os.linux, Os.freebsd => clockLinux,
240 Os.macosx, Os.ios => clockDarwin,240 Os.macosx, Os.ios => clockDarwin,
241 else => @compileError("Unsupported OS"),241 else => @compileError("Unsupported OS"),
242 };242 };