Skip to content

Commit

Permalink
nuke spin_sleep dependency
Browse files Browse the repository at this point in the history
We were only using it for one single function. We can simply copy that
function into the codebase and be done with it. With the added benefit
of constifying the accuracy duration value.
  • Loading branch information
LGFae committed May 26, 2024
1 parent 3b27041 commit 1b314ba
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ rustix = { version = "0.38", default-features = false, features = [ "event" ] }
libc = "0.2"

keyframe = "1.1"
spin_sleep = "1.2"

sd-notify = { version = "0.4.1" }

Expand Down
2 changes: 1 addition & 1 deletion daemon/src/animations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl Animator {

crate::wallpaper::attach_buffers_and_damange_surfaces(&wallpapers);
let timeout = duration.saturating_sub(now.elapsed());
spin_sleep::sleep(timeout);
crate::spin_sleep(timeout);
crate::wallpaper::commit_wallpapers(&wallpapers);

now = std::time::Instant::now();
Expand Down
2 changes: 1 addition & 1 deletion daemon/src/animations/transitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a> Transition<'a> {
}
crate::wallpaper::attach_buffers_and_damange_surfaces(self.wallpapers);
let timeout = self.fps.saturating_sub(now.elapsed());
spin_sleep::sleep(timeout);
crate::spin_sleep(timeout);
crate::wallpaper::commit_wallpapers(self.wallpapers);
*now = Instant::now();
}
Expand Down
16 changes: 16 additions & 0 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,19 @@ pub fn is_daemon_running(addr: &PathBuf) -> Result<bool, String> {
_ => Err("Daemon did not return Answer::Ping, as expected".to_string()),
}
}

/// copy-pasted from the `spin_sleep` crate on crates.io
///
/// This will sleep for an amount of time we can roughly expected the OS to still be precise enough
/// for frame timing (125 us, currently).
fn spin_sleep(duration: std::time::Duration) {
const ACCURACY: std::time::Duration = std::time::Duration::new(0, 125_000);
let start = std::time::Instant::now();
if duration > ACCURACY {
std::thread::sleep(duration - ACCURACY);
}

while start.elapsed() < duration {
std::thread::yield_now();
}
}

0 comments on commit 1b314ba

Please sign in to comment.