Skip to content

Commit

Permalink
JitterRng: port PR dhardy#63 to fix on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Nov 25, 2017
1 parent cb84d54 commit fdaab7e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/jitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ impl JitterRng {
}
}

#[cfg(not(any(target_os = "macos", target_os = "ios")))]
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))]
fn get_nstime() -> u64 {
use std::time::{SystemTime, UNIX_EPOCH};

Expand All @@ -678,6 +678,21 @@ fn get_nstime() -> u64 {
unsafe { libc::mach_absolute_time() }
}

#[cfg(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<T>(dummy: T) -> T {
Expand Down

0 comments on commit fdaab7e

Please sign in to comment.