Remove parking_lot dependency (#846)
The standard library is using a similar implementation to parking_lot now. Other than APIs that are unstable, there shouldn't be that much of a reason to rely on parking_lot anymore. Parts of the cpal codebase already are using std locks. This PR removes the remaining parking_lot uses and replaces them with the standard library's.
This commit is contained in:
parent
4eec3e3441
commit
bdbbf75d82
8 changed files with 19 additions and 29 deletions
|
|
@ -41,18 +41,15 @@ windows = { version = "0.52.0", features = [
|
||||||
]}
|
]}
|
||||||
asio-sys = { version = "0.2", path = "asio-sys", optional = true }
|
asio-sys = { version = "0.2", path = "asio-sys", optional = true }
|
||||||
num-traits = { version = "0.2.6", optional = true }
|
num-traits = { version = "0.2.6", optional = true }
|
||||||
parking_lot = "0.12"
|
|
||||||
|
|
||||||
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd"))'.dependencies]
|
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd"))'.dependencies]
|
||||||
alsa = "0.8"
|
alsa = "0.8"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
parking_lot = "0.12"
|
|
||||||
jack = { version = "0.11", optional = true }
|
jack = { version = "0.11", optional = true }
|
||||||
|
|
||||||
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
|
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
|
||||||
core-foundation-sys = "0.8.2" # For linking to CoreFoundation.framework and handling device name `CFString`s.
|
core-foundation-sys = "0.8.2" # For linking to CoreFoundation.framework and handling device name `CFString`s.
|
||||||
mach2 = "0.4" # For access to mach_timebase type.
|
mach2 = "0.4" # For access to mach_timebase type.
|
||||||
parking_lot = "0.12"
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dependencies]
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
coreaudio-rs = { version = "0.11", default-features = false, features = ["audio_unit", "core_audio"] }
|
coreaudio-rs = { version = "0.11", default-features = false, features = ["audio_unit", "core_audio"] }
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
use super::alsa;
|
use super::alsa;
|
||||||
use super::parking_lot::Mutex;
|
|
||||||
use super::{Device, DeviceHandles};
|
use super::{Device, DeviceHandles};
|
||||||
use crate::{BackendSpecificError, DevicesError};
|
use crate::{BackendSpecificError, DevicesError};
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
/// ALSA's implementation for `Devices`.
|
/// ALSA's implementation for `Devices`.
|
||||||
pub struct Devices {
|
pub struct Devices {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
extern crate alsa;
|
extern crate alsa;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate parking_lot;
|
|
||||||
|
|
||||||
use self::alsa::poll::Descriptors;
|
use self::alsa::poll::Descriptors;
|
||||||
use self::parking_lot::Mutex;
|
|
||||||
use crate::traits::{DeviceTrait, HostTrait, StreamTrait};
|
use crate::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
use crate::{
|
use crate::{
|
||||||
BackendSpecificError, BufferSize, BuildStreamError, ChannelCount, Data,
|
BackendSpecificError, BufferSize, BuildStreamError, ChannelCount, Data,
|
||||||
|
|
@ -14,7 +12,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread::{self, JoinHandle};
|
use std::thread::{self, JoinHandle};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::vec::IntoIter as VecIntoIter;
|
use std::vec::IntoIter as VecIntoIter;
|
||||||
|
|
@ -252,6 +250,7 @@ impl Device {
|
||||||
let handle_result = self
|
let handle_result = self
|
||||||
.handles
|
.handles
|
||||||
.lock()
|
.lock()
|
||||||
|
.unwrap()
|
||||||
.take(&self.name, stream_type)
|
.take(&self.name, stream_type)
|
||||||
.map_err(|e| (e, e.errno()));
|
.map_err(|e| (e, e.errno()));
|
||||||
|
|
||||||
|
|
@ -311,7 +310,7 @@ impl Device {
|
||||||
&self,
|
&self,
|
||||||
stream_t: alsa::Direction,
|
stream_t: alsa::Direction,
|
||||||
) -> Result<VecIntoIter<SupportedStreamConfigRange>, SupportedStreamConfigsError> {
|
) -> Result<VecIntoIter<SupportedStreamConfigRange>, SupportedStreamConfigsError> {
|
||||||
let mut guard = self.handles.lock();
|
let mut guard = self.handles.lock().unwrap();
|
||||||
let handle_result = guard
|
let handle_result = guard
|
||||||
.get_mut(&self.name, stream_t)
|
.get_mut(&self.name, stream_t)
|
||||||
.map_err(|e| (e, e.errno()));
|
.map_err(|e| (e, e.errno()));
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
pub type SupportedInputConfigs = std::vec::IntoIter<SupportedStreamConfigRange>;
|
pub type SupportedInputConfigs = std::vec::IntoIter<SupportedStreamConfigRange>;
|
||||||
pub type SupportedOutputConfigs = std::vec::IntoIter<SupportedStreamConfigRange>;
|
pub type SupportedOutputConfigs = std::vec::IntoIter<SupportedStreamConfigRange>;
|
||||||
|
|
||||||
use super::parking_lot::Mutex;
|
|
||||||
use super::sys;
|
use super::sys;
|
||||||
use crate::BackendSpecificError;
|
use crate::BackendSpecificError;
|
||||||
use crate::DefaultStreamConfigError;
|
use crate::DefaultStreamConfigError;
|
||||||
|
|
@ -15,7 +14,7 @@ use crate::SupportedStreamConfigRange;
|
||||||
use crate::SupportedStreamConfigsError;
|
use crate::SupportedStreamConfigsError;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::sync::atomic::AtomicI32;
|
use std::sync::atomic::AtomicI32;
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
/// A ASIO Device
|
/// A ASIO Device
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
extern crate asio_sys as sys;
|
extern crate asio_sys as sys;
|
||||||
extern crate parking_lot;
|
|
||||||
|
|
||||||
use crate::traits::{DeviceTrait, HostTrait, StreamTrait};
|
use crate::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,13 @@ extern crate asio_sys as sys;
|
||||||
extern crate num_traits;
|
extern crate num_traits;
|
||||||
|
|
||||||
use self::num_traits::PrimInt;
|
use self::num_traits::PrimInt;
|
||||||
use super::parking_lot::Mutex;
|
|
||||||
use super::Device;
|
use super::Device;
|
||||||
use crate::{
|
use crate::{
|
||||||
BackendSpecificError, BufferSize, BuildStreamError, Data, InputCallbackInfo,
|
BackendSpecificError, BufferSize, BuildStreamError, Data, InputCallbackInfo,
|
||||||
OutputCallbackInfo, PauseStreamError, PlayStreamError, SampleFormat, StreamConfig, StreamError,
|
OutputCallbackInfo, PauseStreamError, PlayStreamError, SampleFormat, StreamConfig, StreamError,
|
||||||
};
|
};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
pub struct Stream {
|
pub struct Stream {
|
||||||
|
|
@ -77,7 +76,7 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
// There is 0% chance of lock contention the host only locks when recreating streams.
|
// There is 0% chance of lock contention the host only locks when recreating streams.
|
||||||
let stream_lock = asio_streams.lock();
|
let stream_lock = asio_streams.lock().unwrap();
|
||||||
let asio_stream = match stream_lock.input {
|
let asio_stream = match stream_lock.input {
|
||||||
Some(ref asio_stream) => asio_stream,
|
Some(ref asio_stream) => asio_stream,
|
||||||
None => return,
|
None => return,
|
||||||
|
|
@ -281,7 +280,7 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
// There is 0% chance of lock contention the host only locks when recreating streams.
|
// There is 0% chance of lock contention the host only locks when recreating streams.
|
||||||
let mut stream_lock = asio_streams.lock();
|
let mut stream_lock = asio_streams.lock().unwrap();
|
||||||
let asio_stream = match stream_lock.output {
|
let asio_stream = match stream_lock.output {
|
||||||
Some(ref mut asio_stream) => asio_stream,
|
Some(ref mut asio_stream) => asio_stream,
|
||||||
None => return,
|
None => return,
|
||||||
|
|
@ -518,7 +517,7 @@ impl Device {
|
||||||
Err(_) => Err(BuildStreamError::StreamConfigNotSupported),
|
Err(_) => Err(BuildStreamError::StreamConfigNotSupported),
|
||||||
}?;
|
}?;
|
||||||
let num_channels = config.channels as usize;
|
let num_channels = config.channels as usize;
|
||||||
let mut streams = self.asio_streams.lock();
|
let mut streams = self.asio_streams.lock().unwrap();
|
||||||
|
|
||||||
let buffer_size = match config.buffer_size {
|
let buffer_size = match config.buffer_size {
|
||||||
BufferSize::Fixed(v) => Some(v as i32),
|
BufferSize::Fixed(v) => Some(v as i32),
|
||||||
|
|
@ -565,7 +564,7 @@ impl Device {
|
||||||
Err(_) => Err(BuildStreamError::StreamConfigNotSupported),
|
Err(_) => Err(BuildStreamError::StreamConfigNotSupported),
|
||||||
}?;
|
}?;
|
||||||
let num_channels = config.channels as usize;
|
let num_channels = config.channels as usize;
|
||||||
let mut streams = self.asio_streams.lock();
|
let mut streams = self.asio_streams.lock().unwrap();
|
||||||
|
|
||||||
let buffer_size = match config.buffer_size {
|
let buffer_size = match config.buffer_size {
|
||||||
BufferSize::Fixed(v) => Some(v as i32),
|
BufferSize::Fixed(v) => Some(v as i32),
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ use crate::{
|
||||||
SupportedBufferSize, SupportedStreamConfig, SupportedStreamConfigRange,
|
SupportedBufferSize, SupportedStreamConfig, SupportedStreamConfigRange,
|
||||||
SupportedStreamConfigsError,
|
SupportedStreamConfigsError,
|
||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
@ -36,7 +35,7 @@ use std::os::raw::c_char;
|
||||||
use std::ptr::null;
|
use std::ptr::null;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::sync::mpsc::{channel, RecvTimeoutError};
|
use std::sync::mpsc::{channel, RecvTimeoutError};
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
pub use self::enumerate::{
|
pub use self::enumerate::{
|
||||||
|
|
@ -454,7 +453,7 @@ where
|
||||||
E: FnMut(StreamError) + Send + 'static,
|
E: FnMut(StreamError) + Send + 'static,
|
||||||
{
|
{
|
||||||
let stream_copy = stream.clone();
|
let stream_copy = stream.clone();
|
||||||
let mut stream_inner = stream.inner.lock();
|
let mut stream_inner = stream.inner.lock().unwrap();
|
||||||
stream_inner._disconnect_listener = Some(AudioObjectPropertyListener::new(
|
stream_inner._disconnect_listener = Some(AudioObjectPropertyListener::new(
|
||||||
stream_inner.device_id,
|
stream_inner.device_id,
|
||||||
AudioObjectPropertyAddress {
|
AudioObjectPropertyAddress {
|
||||||
|
|
@ -464,7 +463,7 @@ where
|
||||||
},
|
},
|
||||||
move || {
|
move || {
|
||||||
let _ = stream_copy.pause();
|
let _ = stream_copy.pause();
|
||||||
(error_callback.lock())(StreamError::DeviceNotAvailable);
|
(error_callback.lock().unwrap())(StreamError::DeviceNotAvailable);
|
||||||
},
|
},
|
||||||
)?);
|
)?);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -587,7 +586,7 @@ impl Device {
|
||||||
// TODO: Need a better way to get delay, for now we assume a double-buffer offset.
|
// TODO: Need a better way to get delay, for now we assume a double-buffer offset.
|
||||||
let callback = match host_time_to_stream_instant(args.time_stamp.mHostTime) {
|
let callback = match host_time_to_stream_instant(args.time_stamp.mHostTime) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
(error_callback.lock())(err.into());
|
(error_callback.lock().unwrap())(err.into());
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
Ok(cb) => cb,
|
Ok(cb) => cb,
|
||||||
|
|
@ -617,7 +616,7 @@ impl Device {
|
||||||
add_disconnect_listener(&stream, error_callback_disconnect)?;
|
add_disconnect_listener(&stream, error_callback_disconnect)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.inner.lock().audio_unit.start()?;
|
stream.inner.lock().unwrap().audio_unit.start()?;
|
||||||
|
|
||||||
Ok(stream)
|
Ok(stream)
|
||||||
}
|
}
|
||||||
|
|
@ -691,7 +690,7 @@ impl Device {
|
||||||
|
|
||||||
let callback = match host_time_to_stream_instant(args.time_stamp.mHostTime) {
|
let callback = match host_time_to_stream_instant(args.time_stamp.mHostTime) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
(error_callback.lock())(err.into());
|
(error_callback.lock().unwrap())(err.into());
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
Ok(cb) => cb,
|
Ok(cb) => cb,
|
||||||
|
|
@ -722,7 +721,7 @@ impl Device {
|
||||||
add_disconnect_listener(&stream, error_callback_disconnect)?;
|
add_disconnect_listener(&stream, error_callback_disconnect)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.inner.lock().audio_unit.start()?;
|
stream.inner.lock().unwrap().audio_unit.start()?;
|
||||||
|
|
||||||
Ok(stream)
|
Ok(stream)
|
||||||
}
|
}
|
||||||
|
|
@ -896,7 +895,7 @@ impl Stream {
|
||||||
|
|
||||||
impl StreamTrait for Stream {
|
impl StreamTrait for Stream {
|
||||||
fn play(&self) -> Result<(), PlayStreamError> {
|
fn play(&self) -> Result<(), PlayStreamError> {
|
||||||
let mut stream = self.inner.lock();
|
let mut stream = self.inner.lock().unwrap();
|
||||||
|
|
||||||
if !stream.playing {
|
if !stream.playing {
|
||||||
if let Err(e) = stream.audio_unit.start() {
|
if let Err(e) = stream.audio_unit.start() {
|
||||||
|
|
@ -910,7 +909,7 @@ impl StreamTrait for Stream {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pause(&self) -> Result<(), PauseStreamError> {
|
fn pause(&self) -> Result<(), PauseStreamError> {
|
||||||
let mut stream = self.inner.lock();
|
let mut stream = self.inner.lock().unwrap();
|
||||||
|
|
||||||
if stream.playing {
|
if stream.playing {
|
||||||
if let Err(e) = stream.audio_unit.stop() {
|
if let Err(e) = stream.audio_unit.stop() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
extern crate coreaudio;
|
extern crate coreaudio;
|
||||||
extern crate parking_lot;
|
|
||||||
|
|
||||||
use self::coreaudio::sys::{
|
use self::coreaudio::sys::{
|
||||||
kAudioFormatFlagIsFloat, kAudioFormatFlagIsPacked, kAudioFormatLinearPCM,
|
kAudioFormatFlagIsFloat, kAudioFormatFlagIsPacked, kAudioFormatLinearPCM,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue