Cleanup Windows CPUTimer

This commit is contained in:
Clemens Wasser 2022-09-06 22:43:51 +02:00 committed by David Peter
parent a596c70c33
commit 7db6178dfa
2 changed files with 7 additions and 2 deletions

View File

@ -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]

View File

@ -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<unsafe extern "system" fn(ProcessHandle: HANDLE) -> 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))]