Skip to content

Commit

Permalink
Fix windows usage
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic committed Jan 1, 2024
1 parent b12c1ff commit 286fbcd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Default for SpinSleeper {
#[inline]
fn default() -> Self {
#[cfg(windows)]
let accuracy = *MIN_TIME_PERIOD * 1_000_000;
let accuracy = windows::min_time_period() * 1_000_000;
#[cfg(not(windows))]
let accuracy = DEFAULT_NATIVE_SLEEP_ACCURACY;

Expand Down Expand Up @@ -198,13 +198,11 @@ pub enum SpinStrategy {
/// * !Windows `YieldThread`
impl Default for SpinStrategy {
#[inline]
#[cfg(windows)]
fn default() -> Self {
Self::SpinLoopHint
}
#[inline]
#[cfg(not(windows))]
fn default() -> Self {
#[cfg(windows)]
return Self::SpinLoopHint;

#[cfg(not(windows))]
Self::YieldThread
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use winapi::{

#[inline]
pub fn native_sleep(duration: Duration) {
let min_time_period = win_min_time_period();
let min_time_period = min_time_period();
unsafe {
timeBeginPeriod(min_time_period);
std::thread::sleep(duration);
timeEndPeriod(min_time_period);
}
}

fn win_min_time_period() -> UINT {
pub(crate) fn min_time_period() -> UINT {
static MIN_TIME_PERIOD: OnceLock<UINT> = OnceLock::new();

*MIN_TIME_PERIOD.get_or_init(|| {
Expand Down

0 comments on commit 286fbcd

Please sign in to comment.