diff --git a/coreaudio-sys-utils/src/dispatch.rs b/coreaudio-sys-utils/src/dispatch.rs index ad4d396..f6106b3 100644 --- a/coreaudio-sys-utils/src/dispatch.rs +++ b/coreaudio-sys-utils/src/dispatch.rs @@ -5,6 +5,14 @@ use std::mem; use std::os::raw::c_void; use std::ptr; use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::OnceLock; + +pub const DISPATCH_QUEUE_LABEL: &str = "org.mozilla.cubeb"; + +pub fn get_serial_queue_singleton() -> &'static Queue { + static SERIAL_QUEUE: OnceLock = OnceLock::new(); + SERIAL_QUEUE.get_or_init(|| Queue::new(DISPATCH_QUEUE_LABEL)) +} // Queue: A wrapper around `dispatch_queue_t` that is always serial. // ------------------------------------------------------------------------------------------------ @@ -197,6 +205,9 @@ impl Clone for Queue { } } +unsafe impl Send for Queue {} +unsafe impl Sync for Queue {} + #[test] fn run_tasks_in_order() { let mut visited = Vec::::new(); diff --git a/src/backend/mod.rs b/src/backend/mod.rs index d57b3cf..b616fad 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -54,7 +54,6 @@ const NO_ERR: OSStatus = 0; const AU_OUT_BUS: AudioUnitElement = 0; const AU_IN_BUS: AudioUnitElement = 1; -const DISPATCH_QUEUE_LABEL: &str = "org.mozilla.cubeb"; const PRIVATE_AGGREGATE_DEVICE_NAME: &str = "CubebAggregateDevice"; const VOICEPROCESSING_AGGREGATE_DEVICE_NAME: &str = "VPAUAggregateAudioDevice";