in src/backend/mod.rs [4858:4899]
fn destroy(&mut self) {
self.queue.debug_assert_is_current();
if self
.core_stream_data
.uninstall_system_changed_callback()
.is_err()
{
cubeb_log!(
"({:p}) Could not uninstall the system changed callback",
self as *const AudioUnitStream
);
}
if self
.core_stream_data
.uninstall_device_changed_callback()
.is_err()
{
cubeb_log!(
"({:p}) Could not uninstall all device change listeners",
self as *const AudioUnitStream
);
}
// Execute the stream destroy work.
self.destroy_pending.store(true, Ordering::SeqCst);
// Call stop_audiounits to avoid potential data race. If there is a running data callback,
// which locks a mutex inside CoreAudio framework, then this call will block the current
// thread until the callback is finished since this call asks to lock a mutex inside
// CoreAudio framework that is used by the data callback.
if !self.stopped.swap(true, Ordering::SeqCst) {
self.core_stream_data.stop_audiounits();
}
self.destroy_internal();
cubeb_log!(
"Cubeb stream ({:p}) destroyed successful.",
self as *const AudioUnitStream
);
}