authorgravatar for shritesh@shritesh.comShritesh Bhattarai <shritesh@shritesh.com> 2019-04-30 20:43:43-05:00
committergravatar for shritesh@shritesh.comShritesh Bhattarai <shritesh@shritesh.com> 2019-04-30 20:43:43-05:00
logd395ed2d403aa0ff57c493052e3675de23292424
tree3d5fb6d6a3de329464e56a5face49e785e76e807
parent0ce05fa621ba95ba3ce98f99cb14fec549409069

wasi: implement timestamp


2 files changed, 17 insertions(+), 4 deletions(-)

std/os/time.zig+13
......@@ -7,6 +7,7 @@ const testing = std.testing;
77const windows = std.os.windows;
88const linux = std.os.linux;
99const darwin = std.os.darwin;
10const wasi = std.os.wasi;
1011const posix = std.os.posix;
1112
1213pub const epoch = @import("epoch.zig");
......@@ -64,9 +65,21 @@ pub const milliTimestamp = switch (builtin.os) {
6465 Os.windows => milliTimestampWindows,
6566 Os.linux, Os.freebsd, Os.netbsd => milliTimestampPosix,
6667 Os.macosx, Os.ios => milliTimestampDarwin,
68 Os.wasi => milliTimestampWasi,
6769 else => @compileError("Unsupported OS"),
6870};
6971
72fn milliTimestampWasi() u64 {
73 var ns: wasi.timestamp_t = undefined;
74
75 // TODO: Verify that precision is ignored
76 const err = wasi.clock_time_get(wasi.CLOCK_REALTIME, 1, &ns);
77 debug.assert(err == wasi.ESUCCESS);
78
79 const ns_per_ms = 1000;
80 return @divFloor(ns, ns_per_ms);
81}
82
7083fn milliTimestampWindows() u64 {
7184 //FileTime has a granularity of 100 nanoseconds
7285 // and uses the NTFS/Windows epoch
std/os/wasi/core.zig+4-4
......@@ -10,10 +10,10 @@ pub const ciovec_t = extern struct {
1010 buf_len: usize,
1111};
1212
13pub const CLOCK_REALTIME = 0;
14pub const CLOCK_MONOTONIC = 1;
15pub const CLOCK_PROCESS_CPUTIME_ID = 2;
16pub const CLOCK_THREAD_CPUTIME_ID = 3;
13pub const CLOCK_REALTIME: clockid_t = 0;
14pub const CLOCK_MONOTONIC: clockid_t = 1;
15pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2;
16pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3;
1717
1818pub const SIGABRT: signal_t = 6;
1919