Skip to content

Commit 3f46e65

Browse files
committed
remove Windows-specific sleep code; no longer necessary as of Rust 1.75
Rust 1.75 changed thread::sleep to use high-resolution timers on Windows instead of Sleep() see rust-lang/rust#116461
1 parent 38aefcd commit 3f46e65

File tree

8 files changed

+7
-31
lines changed

8 files changed

+7
-31
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ toml = "0.8"
4747
wasm-bindgen = "0.2"
4848
wasm-bindgen-futures = "0.4"
4949
web-time = "1"
50-
windows = "0.58"
5150
winit = "0.30"
5251
wgpu = "23"
5352
xrandr = "0.2"

common/jgenesis-common/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ log = { workspace = true }
2121
serde = { workspace = true, optional = true }
2222
time = { workspace = true }
2323

24-
[target.'cfg(target_os = "windows")'.dependencies]
25-
windows = { workspace = true, features = ["Win32_Media"] }
26-
2724
[target.'cfg(target_arch = "wasm32")'.dependencies]
2825
js-sys = { workspace = true }
2926

common/jgenesis-common/src/lib.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,6 @@ pub mod input;
55
pub mod num;
66
pub mod timeutils;
77

8-
use cfg_if::cfg_if;
9-
use std::thread;
10-
use std::time::Duration;
11-
12-
#[inline]
13-
pub fn sleep(duration: Duration) {
14-
cfg_if! {
15-
if #[cfg(target_os = "windows")] {
16-
// SAFETY: thread::sleep cannot panic, so timeEndPeriod will always be called after timeBeginPeriod.
17-
unsafe {
18-
windows::Win32::Media::timeBeginPeriod(1);
19-
thread::sleep(duration);
20-
windows::Win32::Media::timeEndPeriod(1);
21-
}
22-
} else {
23-
thread::sleep(duration);
24-
}
25-
}
26-
}
27-
288
#[inline]
299
#[must_use]
3010
pub fn is_appimage_build() -> bool {

frontend/jgenesis-gui/src/emuthread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ fn collect_input(
693693
}
694694
}
695695

696-
jgenesis_common::sleep(Duration::from_millis(10));
696+
thread::sleep(Duration::from_millis(10));
697697
}
698698
}
699699

frontend/jgenesis-native-driver/src/mainloop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ use std::error::Error;
4848
use std::ffi::NulError;
4949
use std::fmt::Debug;
5050
use std::hash::Hash;
51-
use std::io;
5251
use std::path::{Path, PathBuf};
5352
use std::rc::Rc;
5453
use std::sync::LazyLock;
5554
use std::time::Duration;
55+
use std::{io, thread};
5656
use thiserror::Error;
5757

5858
const MODAL_DURATION: Duration = Duration::from_secs(3);
@@ -570,7 +570,7 @@ where
570570

571571
if !should_run_emulator {
572572
// Don't spin loop when the emulator is paused or rewinding
573-
jgenesis_common::sleep(Duration::from_millis(1));
573+
thread::sleep(Duration::from_millis(1));
574574
}
575575

576576
Ok(None)

frontend/jgenesis-native-driver/src/mainloop/audio.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use jgenesis_common::audio::DynamicResamplingRate;
33
use jgenesis_common::frontend::AudioOutput;
44
use sdl2::AudioSubsystem;
55
use sdl2::audio::{AudioQueue, AudioSpecDesired};
6+
use std::thread;
67
use std::time::Duration;
78
use thiserror::Error;
89

@@ -167,7 +168,7 @@ impl AudioOutput for SdlAudioOutput {
167168
if self.audio_sync {
168169
// Block until audio queue is not full
169170
while self.audio_queue_len_samples() > audio_buffer_threshold {
170-
jgenesis_common::sleep(Duration::from_micros(250));
171+
thread::sleep(Duration::from_micros(250));
171172
}
172173
} else if self.audio_queue_len_samples() > audio_buffer_threshold {
173174
// Audio queue is full; drop samples

frontend/jgenesis-renderer/src/renderer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::collections::HashMap;
77
use std::error::Error;
88
use std::fmt::Debug;
99
use std::time::Duration;
10-
use std::{cmp, iter};
10+
use std::{cmp, iter, thread};
1111
use thiserror::Error;
1212
use wgpu::util::DeviceExt;
1313

@@ -960,7 +960,7 @@ impl FrameTimeTracker {
960960
let mut now = timeutils::current_time_nanos();
961961
let next_frame_time = self.last_frame_time_nanos + self.frame_interval_nanos;
962962
while now < next_frame_time {
963-
jgenesis_common::sleep(Duration::from_micros(250));
963+
thread::sleep(Duration::from_micros(250));
964964
now = timeutils::current_time_nanos();
965965
}
966966

0 commit comments

Comments
 (0)