aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-11-24 22:43:15 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-11-24 22:48:30 +0400
commitae47f2116decc046836c9e02880af79bf5f507ee (patch)
tree0e32022d5efa9b2fe2a515448b3d2422c8ae043a /src/utils.rs
parent9f24b48d8fc14169db5e676f25595f0f7fe17017 (diff)
downloadniri-ae47f2116decc046836c9e02880af79bf5f507ee.tar.gz
niri-ae47f2116decc046836c9e02880af79bf5f507ee.tar.bz2
niri-ae47f2116decc046836c9e02880af79bf5f507ee.zip
Move command spawning to a thread
It was showing up on profiles causing dropped frames.
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs23
1 files changed, 22 insertions, 1 deletions
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<OsStr>, args: impl IntoIterator<Item = impl AsRef<OsStr>>) {
+pub fn spawn<T: AsRef<OsStr> + Send + 'static>(command: Vec<T>) {
+ 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<OsStr>, args: impl IntoIterator<Item = impl AsRef<OsStr>>) {
let _span = tracy_client::span!();
let command = command.as_ref();