| 24 | } // namespace |
| 25 | |
| 26 | WasiExpect<void> Clock::clockResGet(__wasi_clockid_t Id, |
| 27 | __wasi_timestamp_t &Resolution) noexcept { |
| 28 | switch (Id) { |
| 29 | case __WASI_CLOCKID_MONOTONIC: { |
| 30 | const std::chrono::nanoseconds Result = |
| 31 | std::chrono::nanoseconds(std::chrono::seconds{1}) / kFrequency; |
| 32 | Resolution = static_cast<__wasi_timestamp_t>(Result.count()); |
| 33 | return {}; |
| 34 | } |
| 35 | case __WASI_CLOCKID_REALTIME: |
| 36 | case __WASI_CLOCKID_PROCESS_CPUTIME_ID: |
| 37 | case __WASI_CLOCKID_THREAD_CPUTIME_ID: { |
| 38 | ULONG_ MinimumResolution; |
| 39 | ULONG_ MaximumResolution; |
| 40 | ULONG_ CurrentResolution; |
| 41 | if (auto Res = NtQueryTimerResolution( |
| 42 | &MinimumResolution, &MaximumResolution, &CurrentResolution); |
| 43 | unlikely(!NT_SUCCESS_(Res))) { |
| 44 | return WasiUnexpect(detail::fromLastError(RtlNtStatusToDosError(Res))); |
| 45 | } |
| 46 | const std::chrono::nanoseconds Result = FiletimeDuration{CurrentResolution}; |
| 47 | Resolution = static_cast<__wasi_timestamp_t>(Result.count()); |
| 48 | return {}; |
| 49 | } |
| 50 | default: |
| 51 | return WasiUnexpect(__WASI_ERRNO_NOSYS); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | WasiExpect<void> Clock::clockTimeGet(__wasi_clockid_t Id, |
| 56 | __wasi_timestamp_t Precision |
no test coverage detected