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:
James Liu 2024-02-24 16:48:53 -08:00 • committed by GitHub
parent 4eec3e3441
commit bdbbf75d82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 19 additions and 29 deletions

View file

@ -28,7 +28,6 @@ use crate::{
SupportedBufferSize, SupportedStreamConfig, SupportedStreamConfigRange,
SupportedStreamConfigsError,
};
use parking_lot::Mutex;
use std::ffi::CStr;
use std::fmt;
use std::mem;
@ -36,7 +35,7 @@ use std::os::raw::c_char;
use std::ptr::null;
use std::slice;
use std::sync::mpsc::{channel, RecvTimeoutError};
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
pub use self::enumerate::{
@ -454,7 +453,7 @@ where
E: FnMut(StreamError) + Send + 'static,
{
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.device_id,
AudioObjectPropertyAddress {
@ -464,7 +463,7 @@ where
},
move || {
let _ = stream_copy.pause();
(error_callback.lock())(StreamError::DeviceNotAvailable);
(error_callback.lock().unwrap())(StreamError::DeviceNotAvailable);
},
)?);
Ok(())
@ -587,7 +586,7 @@ impl Device {
// 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) {
Err(err) => {
(error_callback.lock())(err.into());
(error_callback.lock().unwrap())(err.into());
return Err(());
}
Ok(cb) => cb,
@ -617,7 +616,7 @@ impl Device {
add_disconnect_listener(&stream, error_callback_disconnect)?;
}
stream.inner.lock().audio_unit.start()?;
stream.inner.lock().unwrap().audio_unit.start()?;
Ok(stream)
}
@ -691,7 +690,7 @@ impl Device {
let callback = match host_time_to_stream_instant(args.time_stamp.mHostTime) {
Err(err) => {
(error_callback.lock())(err.into());
(error_callback.lock().unwrap())(err.into());
return Err(());
}
Ok(cb) => cb,
@ -722,7 +721,7 @@ impl Device {
add_disconnect_listener(&stream, error_callback_disconnect)?;
}
stream.inner.lock().audio_unit.start()?;
stream.inner.lock().unwrap().audio_unit.start()?;
Ok(stream)
}
@ -896,7 +895,7 @@ impl Stream {
impl StreamTrait for Stream {
fn play(&self) -> Result<(), PlayStreamError> {
let mut stream = self.inner.lock();
let mut stream = self.inner.lock().unwrap();
if !stream.playing {
if let Err(e) = stream.audio_unit.start() {
@ -910,7 +909,7 @@ impl StreamTrait for Stream {
}
fn pause(&self) -> Result<(), PauseStreamError> {
let mut stream = self.inner.lock();
let mut stream = self.inner.lock().unwrap();
if stream.playing {
if let Err(e) = stream.audio_unit.stop() {