mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
time: add uefi support
This commit is contained in:
parent
a86cd91389
commit
23adf09579
@ -114,6 +114,13 @@ pub fn nanoTimestamp() i128 {
|
||||
return ns;
|
||||
}
|
||||
|
||||
if (builtin.os.tag == .uefi) {
|
||||
var value: std.os.uefi.Time = undefined;
|
||||
const status = std.os.uefi.system_table.runtime_services.getTime(&value, null);
|
||||
assert(status == .Success);
|
||||
return @as(i128, @intCast(value.toEpoch())) * ms_per_s;
|
||||
}
|
||||
|
||||
var ts: os.timespec = undefined;
|
||||
os.clock_gettime(os.CLOCK.REALTIME, &ts) catch |err| switch (err) {
|
||||
error.UnsupportedClock, error.Unexpected => return 0, // "Precision of timing depends on hardware and OS".
|
||||
@ -176,7 +183,7 @@ pub const Instant = struct {
|
||||
// true if we should use clock_gettime()
|
||||
const is_posix = switch (builtin.os.tag) {
|
||||
.wasi => builtin.link_libc,
|
||||
.windows => false,
|
||||
.windows, .uefi => false,
|
||||
else => true,
|
||||
};
|
||||
|
||||
@ -197,6 +204,13 @@ pub const Instant = struct {
|
||||
return Instant{ .timestamp = ns };
|
||||
}
|
||||
|
||||
if (builtin.os.tag == .uefi) {
|
||||
var value: std.os.uefi.Time = undefined;
|
||||
const status = std.os.uefi.system_table.runtime_services.getTime(&value, null);
|
||||
if (status != .Success) return error.Unsupported;
|
||||
return Instant{ .timestamp = value.toEpoch() };
|
||||
}
|
||||
|
||||
// On darwin, use UPTIME_RAW instead of MONOTONIC as it ticks while suspended.
|
||||
// On linux, use BOOTTIME instead of MONOTONIC as it ticks while suspended.
|
||||
// On freebsd derivatives, use MONOTONIC_FAST as currently there's no precision tradeoff.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user