| ... | @@ -52,18 +52,18 @@ pub fn posixSleep(seconds: u63, nanoseconds: u63) void { | ... | @@ -52,18 +52,18 @@ pub fn posixSleep(seconds: u63, nanoseconds: u63) void { |
| 52 | | 52 | |
| 53 | /// Get the posix timestamp, UTC, in seconds | 53 | /// Get the posix timestamp, UTC, in seconds |
| 54 | pub fn timestamp() u64 { | 54 | pub fn timestamp() u64 { |
| 55 | return @divFloor(miliTimestamp(), ms_per_s); | 55 | return @divFloor(milliTimestamp(), ms_per_s); |
| 56 | } | 56 | } |
| 57 | | 57 | |
| 58 | /// Get the posix timestamp, UTC, in nanoseconds | 58 | /// Get the posix timestamp, UTC, in nanoseconds |
| 59 | pub const miliTimestamp = switch(builtin.os) { | 59 | pub const milliTimestamp = switch(builtin.os) { |
| 60 | Os.windows => miliTimestampWindows, | 60 | Os.windows => milliTimestampWindows, |
| 61 | Os.linux => miliTimestampPosix, | 61 | Os.linux => milliTimestampPosix, |
| 62 | Os.macosx, Os.ios => miliTimestampDarwin, | 62 | Os.macosx, Os.ios => milliTimestampDarwin, |
| 63 | else => @compileError("Unsupported OS"), | 63 | else => @compileError("Unsupported OS"), |
| 64 | }; | 64 | }; |
| 65 | | 65 | |
| 66 | fn miliTimestampWindows() u64 { | 66 | fn milliTimestampWindows() u64 { |
| 67 | //FileTime has a granularity of 100 nanoseconds | 67 | //FileTime has a granularity of 100 nanoseconds |
| 68 | // and uses the NTFS/Windows epoch | 68 | // and uses the NTFS/Windows epoch |
| 69 | var ft: i64 = undefined; | 69 | var ft: i64 = undefined; |
| ... | @@ -73,7 +73,7 @@ fn miliTimestampWindows() u64 { | ... | @@ -73,7 +73,7 @@ fn miliTimestampWindows() u64 { |
| 73 | return u64(@divFloor(ft, hns_per_ms) + epoch_adj); | 73 | return u64(@divFloor(ft, hns_per_ms) + epoch_adj); |
| 74 | } | 74 | } |
| 75 | | 75 | |
| 76 | fn miliTimestampDarwin() u64 { | 76 | fn milliTimestampDarwin() u64 { |
| 77 | //Sources suggest MacOS 10.12 has support for | 77 | //Sources suggest MacOS 10.12 has support for |
| 78 | // posix clock_gettime. | 78 | // posix clock_gettime. |
| 79 | var tv: darwin.timeval = undefined; | 79 | var tv: darwin.timeval = undefined; |
| ... | @@ -84,7 +84,7 @@ fn miliTimestampDarwin() u64 { | ... | @@ -84,7 +84,7 @@ fn miliTimestampDarwin() u64 { |
| 84 | return u64(sec_ms) + u64(usec_ms); | 84 | return u64(sec_ms) + u64(usec_ms); |
| 85 | } | 85 | } |
| 86 | | 86 | |
| 87 | fn miliTimestampPosix() u64 { | 87 | fn milliTimestampPosix() u64 { |
| 88 | //From what I can tell there's no reason clock_gettime | 88 | //From what I can tell there's no reason clock_gettime |
| 89 | // should ever fail for us with CLOCK_REALTIME | 89 | // should ever fail for us with CLOCK_REALTIME |
| 90 | var ts: posix.timespec = undefined; | 90 | var ts: posix.timespec = undefined; |
| ... | @@ -238,9 +238,9 @@ test "os.time.timestamp" { | ... | @@ -238,9 +238,9 @@ test "os.time.timestamp" { |
| 238 | const ns_per_ms = (ns_per_s / ms_per_s); | 238 | const ns_per_ms = (ns_per_s / ms_per_s); |
| 239 | const margin = 50; | 239 | const margin = 50; |
| 240 | | 240 | |
| 241 | const time_0 = miliTimestamp(); | 241 | const time_0 = milliTimestamp(); |
| 242 | sleep(0, ns_per_ms); | 242 | sleep(0, ns_per_ms); |
| 243 | const time_1 = miliTimestamp(); | 243 | const time_1 = milliTimestamp(); |
| 244 | const interval = time_1 - time_0; | 244 | const interval = time_1 - time_0; |
| 245 | debug.assert(interval > 0 and interval < margin); | 245 | debug.assert(interval > 0 and interval < margin); |
| 246 | } | 246 | } |