in src/backend/mod.rs [4803:4838]
fn reinit_async(&mut self) {
if self.reinit_pending.swap(true, Ordering::SeqCst) {
// A reinit task is already pending, nothing more to do.
cubeb_log!(
"({:p}) re-init stream task already pending, cancelling request",
self as *const AudioUnitStream
);
return;
}
let queue = self.queue.clone();
// Use a new thread, through the queue, to avoid deadlock when calling
// Get/SetProperties method from inside notify callback
queue.run_async(move || {
cubeb_log!("Reinitialization of stream");
let stm_ptr = self as *const AudioUnitStream;
if self.destroy_pending.load(Ordering::SeqCst) {
cubeb_log!(
"({:p}) stream pending destroy, cancelling reinit task",
stm_ptr
);
return;
}
if self.reinit().is_err() {
self.core_stream_data.close();
self.notify_state_changed(State::Error);
cubeb_log!(
"({:p}) Could not reopen the stream after switching.",
stm_ptr
);
}
self.switching_device.store(false, Ordering::SeqCst);
self.reinit_pending.store(false, Ordering::SeqCst);
});
}