Browse Source

audio_core: sink_stream: Hold the suspend lock when process is stalled.

- Prevents us from clashing with other callers trying to un/stall.
nce_cpp
bunnei 3 years ago
parent
commit
9ac846fece
  1. 11
      src/audio_core/sink/sink_stream.cpp
  2. 5
      src/audio_core/sink/sink_stream.h

11
src/audio_core/sink/sink_stream.cpp

@ -266,19 +266,20 @@ void SinkStream::ProcessAudioOutAndRender(std::span<s16> output_buffer, std::siz
} }
void SinkStream::Stall() { void SinkStream::Stall() {
if (stalled) {
std::scoped_lock lk{stall_guard};
if (stalled_lock) {
return; return;
} }
stalled = true;
system.StallProcesses();
stalled_lock = system.StallProcesses();
} }
void SinkStream::Unstall() { void SinkStream::Unstall() {
if (!stalled) {
std::scoped_lock lk{stall_guard};
if (!stalled_lock) {
return; return;
} }
system.UnstallProcesses(); system.UnstallProcesses();
stalled = false;
stalled_lock.unlock();
} }
} // namespace AudioCore::Sink } // namespace AudioCore::Sink

5
src/audio_core/sink/sink_stream.h

@ -6,6 +6,7 @@
#include <array> #include <array>
#include <atomic> #include <atomic>
#include <memory> #include <memory>
#include <mutex>
#include <span> #include <span>
#include <vector> #include <vector>
@ -240,8 +241,8 @@ private:
f32 system_volume{1.0f}; f32 system_volume{1.0f};
/// Set via IAudioDevice service calls /// Set via IAudioDevice service calls
f32 device_volume{1.0f}; f32 device_volume{1.0f};
/// True if coretiming has been stalled
bool stalled{false};
std::mutex stall_guard;
std::unique_lock<std::mutex> stalled_lock;
}; };
using SinkStreamPtr = std::unique_ptr<SinkStream>; using SinkStreamPtr = std::unique_ptr<SinkStream>;

Loading…
Cancel
Save