From 5aef92cf4fea062378b3e71e805dd930a459ca50 Mon Sep 17 00:00:00 2001 From: Noa <33094578+coolreader18@users.noreply.github.com> Date: Thu, 6 Jan 2022 15:08:54 -0600 Subject: [PATCH] Bring Duration into scope in time.rs --- vm/src/stdlib/time.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/vm/src/stdlib/time.rs b/vm/src/stdlib/time.rs index f097d3221..0af5d219f 100644 --- a/vm/src/stdlib/time.rs +++ b/vm/src/stdlib/time.rs @@ -28,6 +28,7 @@ mod time { naive::{NaiveDate, NaiveDateTime, NaiveTime}, Datelike, Timelike, }; + use std::time::Duration; #[allow(dead_code)] pub(super) const SEC_TO_MS: i64 = 1000; @@ -46,7 +47,7 @@ mod time { #[allow(dead_code)] pub(super) const NS_TO_US: i64 = 1000; - fn duration_since_system_now(vm: &VirtualMachine) -> PyResult { + fn duration_since_system_now(vm: &VirtualMachine) -> PyResult { use std::time::{SystemTime, UNIX_EPOCH}; SystemTime::now() @@ -56,19 +57,19 @@ mod time { // TODO: implement proper monotonic time for wasm/wasi. #[cfg(not(any(unix, windows)))] - fn get_monotonic_time(vm: &VirtualMachine) -> PyResult { + fn get_monotonic_time(vm: &VirtualMachine) -> PyResult { duration_since_system_now(vm) } // TODO: implement proper perf time for wasm/wasi. #[cfg(not(any(unix, windows)))] - fn get_perf_time(vm: &VirtualMachine) -> PyResult { + fn get_perf_time(vm: &VirtualMachine) -> PyResult { duration_since_system_now(vm) } #[cfg(not(unix))] #[pyfunction] - fn sleep(dur: std::time::Duration) { + fn sleep(dur: Duration) { std::thread::sleep(dur); } @@ -233,7 +234,7 @@ mod time { target_os = "fuchsia", target_os = "emscripten", )))] - fn get_thread_time(vm: &VirtualMachine) -> PyResult { + fn get_thread_time(vm: &VirtualMachine) -> PyResult { Err(vm.new_not_implemented_error("thread time unsupported in this system".to_owned())) } @@ -256,7 +257,7 @@ mod time { } #[cfg(all(target_arch = "wasm32", not(target_os = "unknown")))] - fn get_process_time(vm: &VirtualMachine) -> PyResult { + fn get_process_time(vm: &VirtualMachine) -> PyResult { let t: libc::tms = unsafe { let mut t = std::mem::MaybeUninit::uninit(); if libc::times(t.as_mut_ptr()) == -1 { @@ -270,7 +271,7 @@ mod time { #[cfg(not(target_os = "wasi"))] let freq = unsafe { libc::sysconf(libc::_SC_CLK_TCK) }; - Ok(std::time::Duration::from_nanos( + Ok(Duration::from_nanos( time_muldiv(t.tms_utime, SEC_TO_NS, freq) + time_muldiv(t.tms_stime, SEC_TO_NS, freq), )) } @@ -289,7 +290,7 @@ mod time { target_os = "redox", all(target_arch = "wasm32", not(target_os = "unknown")) )))] - fn get_process_time(vm: &VirtualMachine) -> PyResult { + fn get_process_time(vm: &VirtualMachine) -> PyResult { Err(vm.new_not_implemented_error("process time unsupported in this system".to_owned())) }