зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1530715 - P25: Move aggregate_device to a struct within a mutex. r=padenot
The aggregate device of the stream may be created, reinitialized, or destroyed on different threads, so its operations should be in the critical sections. We do create critical sections by our custom mutex. However, this custom mutex will be gradually replaced by the standard Rust mutex in the following patches. To replace the custom mutex, we create a struct wrapped by a Rust mutex and create critical sections by this Rust mutex to do operations for aggregate-device settings. At the end, not only aggregate-device calls, but also other operations that needs to be locked will be operated in the critical section created by this struct. This is the beginning patch to replace the custom mutex in AudioUnitStream. Differential Revision: https://phabricator.services.mozilla.com/D34058 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
3aa1456189
Коммит
43dfd443a9
|
@ -3,4 +3,4 @@ git repository using the update.sh script.
|
|||
|
||||
The cubeb-coreaudio-rs git repository is: https://github.com/ChunMinChang/cubeb-coreaudio-rs
|
||||
|
||||
The git commit ID used was c7f9d00909ef52b4390d70c81d3b36e8001b2386 (2019-06-21 15:51:40 -0700)
|
||||
The git commit ID used was 5841bba86f1245190020c7c6263a4b9ee783f442 (2019-06-25 11:31:39 -0700)
|
||||
|
|
|
@ -2393,6 +2393,25 @@ impl Drop for AudioUnitContext {
|
|||
unsafe impl Send for AudioUnitContext {}
|
||||
unsafe impl Sync for AudioUnitContext {}
|
||||
|
||||
// In the process of defusing our own custom mutex, those variables in the critical sections
|
||||
// created by our own custom mutex will be moved to this struct. As a result, they will still
|
||||
// be in the critical sections but the sections are created by this struct. However, some
|
||||
// struct members don't really need locks to be used since their code paths give thread-safe
|
||||
// guarantees. In fact, the mutex around this struct will be removed at the end of the
|
||||
// mutex-defusing refactoring so it's fine to keep them in this struct for now.
|
||||
#[derive(Debug)]
|
||||
struct StreamDevice {
|
||||
aggregate_device: AggregateDevice,
|
||||
}
|
||||
|
||||
impl Default for StreamDevice {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
aggregate_device: AggregateDevice::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The fisrt two members of the Cubeb stream must be a pointer to its Cubeb context and a void user
|
||||
// defined pointer. The Cubeb interface use this assumption to operate the Cubeb APIs.
|
||||
// #[repr(C)] is used to prevent any padding from being added in the beginning of the AudioUnitStream.
|
||||
|
@ -2454,7 +2473,7 @@ struct AudioUnitStream<'ctx> {
|
|||
input_alive_listener: Option<device_property_listener>,
|
||||
input_source_listener: Option<device_property_listener>,
|
||||
output_source_listener: Option<device_property_listener>,
|
||||
aggregate_device: AggregateDevice,
|
||||
stream_device: Mutex<StreamDevice>,
|
||||
}
|
||||
|
||||
impl<'ctx> AudioUnitStream<'ctx> {
|
||||
|
@ -2516,7 +2535,7 @@ impl<'ctx> AudioUnitStream<'ctx> {
|
|||
input_alive_listener: None,
|
||||
input_source_listener: None,
|
||||
output_source_listener: None,
|
||||
aggregate_device: AggregateDevice::default(),
|
||||
stream_device: Mutex::new(StreamDevice::default()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3324,7 +3343,8 @@ impl<'ctx> AudioUnitStream<'ctx> {
|
|||
out_dev_info.id = device.get_device_id();
|
||||
in_dev_info.flags = device_flags::DEV_INPUT;
|
||||
out_dev_info.flags = device_flags::DEV_OUTPUT;
|
||||
self.aggregate_device = device;
|
||||
let mut stream_device = self.stream_device.lock().unwrap();
|
||||
stream_device.aggregate_device = device;
|
||||
}
|
||||
Err(status) => {
|
||||
cubeb_log!(
|
||||
|
@ -3495,7 +3515,10 @@ impl<'ctx> AudioUnitStream<'ctx> {
|
|||
self.resampler.reset(ptr::null_mut());
|
||||
self.mixer.reset(ptr::null_mut());
|
||||
|
||||
self.aggregate_device = AggregateDevice::default();
|
||||
{
|
||||
let mut stream_device = self.stream_device.lock().unwrap();
|
||||
stream_device.aggregate_device = AggregateDevice::default();
|
||||
}
|
||||
}
|
||||
|
||||
fn destroy_internal(&mut self) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче