From 9486aa39d89cb58ceefdd6483f1f1a3810450228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Kozio=C5=82?= Date: Sun, 22 Nov 2026 22:14:39 +0100 Subject: [PATCH] Audio: a follower's device is looked for without holding the followers' lock The watcher held the followers' lock while it looked for a device that went away and tried to open it again, every second. When Windows refuses an input ("access denied": its microphone privacy setting, or another program holding it), each try takes seconds, and the session, which takes the same lock every second to show the devices, waited with it: the whole interface stuttered and froze while the audio played on (#94). The lock is now taken only to collect retired links and to attach a new one. Co-Authored-By: Claude Opus 5.5 --- crates/faderframe-audio-cpal/src/followers.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/faderframe-audio-cpal/src/followers.rs b/crates/faderframe-audio-cpal/src/followers.rs index feed72fb..0e7566af 100644 --- a/crates/faderframe-audio-cpal/src/followers.rs +++ b/crates/faderframe-audio-cpal/src/followers.rs @@ -210,10 +210,16 @@ pub struct Watcher { } impl Watcher { + /// Looking for a device and opening it can take seconds (Windows + /// refusing an input it does not let FaderFrame use: #94); the + /// followers' lock, which the control side takes to show the devices, + /// is held only to attach a link, never meanwhile. pub fn tick(&mut self) { let now = Instant::now(); - let mut followers = self.followers.lock().unwrap_or_else(|e| e.into_inner()); - followers.collect(); + self.followers + .lock() + .unwrap_or_else(|e| e.into_inner()) + .collect(); for f in &mut self.streams { if f.stream.is_some() && f.failed.load(Ordering::Relaxed) { // Unplugged (or its device otherwise gone): its channels @@ -250,7 +256,12 @@ impl Watcher { ) else { continue; }; - let Some(end) = followers.attach(f.index, open.sample_rate, open.block) else { + let attached = self + .followers + .lock() + .unwrap_or_else(|e| e.into_inner()) + .attach(f.index, open.sample_rate, open.block); + let Some(end) = attached else { continue; }; f.failed.store(false, Ordering::Relaxed);