From ae47f2116decc046836c9e02880af79bf5f507ee Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 24 Nov 2023 22:43:15 +0400 Subject: Move command spawning to a thread It was showing up on profiles causing dropped frames. --- src/utils.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs index 94b5c427..bf25819b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; use std::process::{Command, Stdio}; use std::ptr::null_mut; use std::sync::atomic::{AtomicBool, Ordering}; +use std::thread; use std::time::Duration; use anyhow::{ensure, Context}; @@ -58,7 +59,27 @@ pub static REMOVE_ENV_RUST_BACKTRACE: AtomicBool = AtomicBool::new(false); pub static REMOVE_ENV_RUST_LIB_BACKTRACE: AtomicBool = AtomicBool::new(false); /// Spawns the command to run independently of the compositor. -pub fn spawn(command: impl AsRef, args: impl IntoIterator>) { +pub fn spawn + Send + 'static>(command: Vec) { + let _span = tracy_client::span!(); + + if command.is_empty() { + return; + } + + // Spawning and waiting takes some milliseconds, so do it in a thread. + let res = thread::Builder::new() + .name("Command Spawner".to_owned()) + .spawn(move || { + let (command, args) = command.split_first().unwrap(); + spawn_sync(command, args); + }); + + if let Err(err) = res { + warn!("error spawning a thread to spawn the command: {err:?}"); + } +} + +fn spawn_sync(command: impl AsRef, args: impl IntoIterator>) { let _span = tracy_client::span!(); let command = command.as_ref(); -- cgit