From 7db6178dfa8fadbfdba9df2c45062978fd6299de Mon Sep 17 00:00:00 2001 From: Clemens Wasser Date: Tue, 6 Sep 2022 22:43:51 +0200 Subject: [PATCH] Cleanup Windows CPUTimer --- Cargo.toml | 2 ++ src/timer/windows_timer.rs | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5481be..3b5380a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,8 @@ libc = "0.2" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["processthreadsapi", "minwindef", "winnt", "jobapi2", "tlhelp32"] } + +[target.'cfg(all(windows, not(windows_process_extensions_main_thread_handle)))'.dependencies] once_cell = "1.13" [target.'cfg(target_os="linux")'.dependencies] diff --git a/src/timer/windows_timer.rs b/src/timer/windows_timer.rs index 7253a89..97e12f3 100644 --- a/src/timer/windows_timer.rs +++ b/src/timer/windows_timer.rs @@ -3,7 +3,6 @@ use std::{mem, os::windows::io::AsRawHandle, process, ptr}; -use clap::__macro_refs::once_cell::sync::Lazy; use winapi::{ shared::{ntdef::NTSTATUS, ntstatus::STATUS_SUCCESS}, um::{ @@ -19,10 +18,14 @@ use winapi::{ #[cfg(windows_process_extensions_main_thread_handle)] use winapi::shared::minwindef::DWORD; +#[cfg(not(windows_process_extensions_main_thread_handle))] +use once_cell::sync::Lazy; + use crate::util::units::Second; const HUNDRED_NS_PER_MS: i64 = 10; +#[cfg(not(windows_process_extensions_main_thread_handle))] #[allow(non_upper_case_globals)] static NtResumeProcess: Lazy NTSTATUS> = Lazy::new(|| { @@ -57,7 +60,7 @@ impl CPUTimer { { // SAFETY: The main thread handle is valid let ret = unsafe { ResumeThread(child.main_thread_handle().as_raw_handle()) }; - assert!(ret != -1 as DWORD, "NtResumeProcess failed"); + assert!(ret != -1 as DWORD, "ResumeThread failed"); } #[cfg(not(windows_process_extensions_main_thread_handle))]