From 16c832e0ebee5347a20715bccda04623ee48cbed Mon Sep 17 00:00:00 2001 From: Vikram Auradkar Date: Thu, 22 Sep 2022 22:00:24 +0000 Subject: [PATCH] devices: ac97: windows: Convert mute Mutex to AtomicBool BUG=b:213149155 BUG=b:150630566 BUG=b:236297362 TEST=ran downstream tests Change-Id: Ie7d1650baeeaeea5ee0391d50e61335eb09dcefd Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3967443 Reviewed-by: Alexandre Courbot Commit-Queue: Vikram Auradkar --- devices/src/pci/ac97_bus_master/sys/windows.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/devices/src/pci/ac97_bus_master/sys/windows.rs b/devices/src/pci/ac97_bus_master/sys/windows.rs index d786eeb7b4..3020534834 100644 --- a/devices/src/pci/ac97_bus_master/sys/windows.rs +++ b/devices/src/pci/ac97_bus_master/sys/windows.rs @@ -245,7 +245,7 @@ impl Ac97BusMaster { )?; self.po_info.stream_control = Some(Box::new(NoopStreamControl::new())); self.update_mixer_settings(mixer); - let mute = self.sys.mute.clone(); + let mute = Arc::new(AtomicBool::new(*self.sys.mute.lock())); self.po_info.thread = Some( thread::Builder::new() @@ -351,7 +351,7 @@ fn play_buffer( mem: &GuestMemory, out_buffer: &mut PlaybackBuffer, intermediate_resampler_buffer: &mut IntermediateResamplerBuffer, - mute: &Arc>, + mute: &Arc, ) -> AudioResult<()> { // If the current buffer had any samples in it, mark it as done. if regs.func_regs_mut(Ac97Function::Output).picb > 0 { @@ -362,7 +362,9 @@ fn play_buffer( // If mute is set to true, we want to drop all the audio samples coming from the guest. // We still want to read from the guest to prevent it from thinking there is a buffer // overrun and to make sure the guest is not in a weird state. - if let Some(buffer) = next_guest_buffer(func_regs, mem)?.filter(|_| !*mute.lock()) { + if let Some(buffer) = + next_guest_buffer(func_regs, mem)?.filter(|_| !mute.load(Ordering::Relaxed)) + { // Safe because we know that `buffer` is a volatile slice, which can be converted to // an array of bytes. let buffer_slice = unsafe { slice::from_raw_parts(buffer.as_ptr(), buffer.size()) }; @@ -379,7 +381,7 @@ fn play_buffer( next_period.len(), out.len(), ); - *mute.lock() = true; + mute.store(true, Ordering::Relaxed); out.fill(0); } }) @@ -409,7 +411,7 @@ fn audio_out_thread( thread_run: &AtomicBool, output_stream: Arc>>, mut intermediate_resampler_buffer: IntermediateResamplerBuffer, - mute: Arc>, + mute: Arc, guest_num_channels: usize, ) -> AudioResult<()> { while thread_run.load(Ordering::Relaxed) {