From e87b0a7523385a38dc65216214863935aa741f02 Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Sat, 25 Nov 2017 16:23:33 +0100 Subject: [PATCH] Fix JitterRng on Windows --- src/jitter_rng.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/jitter_rng.rs b/src/jitter_rng.rs index d36cf79aafe..21609dfa456 100644 --- a/src/jitter_rng.rs +++ b/src/jitter_rng.rs @@ -670,7 +670,8 @@ impl JitterRng { } } -#[cfg(all(feature="std", not(any(target_os = "macos", target_os = "ios"))))] +#[cfg(all(feature="std", not(any(target_os = "macos", target_os = "ios", + target_os = "windows"))))] fn get_nstime() -> u64 { use std::time::{SystemTime, UNIX_EPOCH}; @@ -694,6 +695,21 @@ fn get_nstime() -> u64 { unsafe { libc::mach_absolute_time() } } +#[cfg(all(feature="std", any(target_os = "windows")))] +fn get_nstime() -> u64 { + #[allow(non_camel_case_types)] + type LARGE_INTEGER = i64; + #[allow(non_camel_case_types)] + type BOOL = i32; + extern "system" { + fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER) -> BOOL; + } + + let mut t = 0; + unsafe { QueryPerformanceCounter(&mut t); } + t as u64 +} + // A function that is opaque to the optimizer to assist in avoiding dead-code // elimination. Taken from `bencher`. fn black_box(dummy: T) -> T {