diff options
| -rw-r--r-- | src/audio_core/sink/sink_stream.cpp | 11 | ||||
| -rw-r--r-- | src/audio_core/sink/sink_stream.h | 5 | ||||
| -rw-r--r-- | src/core/core.cpp | 11 |
3 files changed, 14 insertions, 13 deletions
diff --git a/src/audio_core/sink/sink_stream.cpp b/src/audio_core/sink/sink_stream.cpp index 849f862b0..67e194e3c 100644 --- a/src/audio_core/sink/sink_stream.cpp +++ b/src/audio_core/sink/sink_stream.cpp | |||
| @@ -266,19 +266,20 @@ void SinkStream::ProcessAudioOutAndRender(std::span<s16> output_buffer, std::siz | |||
| 266 | } | 266 | } |
| 267 | 267 | ||
| 268 | void SinkStream::Stall() { | 268 | void SinkStream::Stall() { |
| 269 | if (stalled) { | 269 | std::scoped_lock lk{stall_guard}; |
| 270 | if (stalled_lock) { | ||
| 270 | return; | 271 | return; |
| 271 | } | 272 | } |
| 272 | stalled = true; | 273 | stalled_lock = system.StallProcesses(); |
| 273 | system.StallProcesses(); | ||
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | void SinkStream::Unstall() { | 276 | void SinkStream::Unstall() { |
| 277 | if (!stalled) { | 277 | std::scoped_lock lk{stall_guard}; |
| 278 | if (!stalled_lock) { | ||
| 278 | return; | 279 | return; |
| 279 | } | 280 | } |
| 280 | system.UnstallProcesses(); | 281 | system.UnstallProcesses(); |
| 281 | stalled = false; | 282 | stalled_lock.unlock(); |
| 282 | } | 283 | } |
| 283 | 284 | ||
| 284 | } // namespace AudioCore::Sink | 285 | } // namespace AudioCore::Sink |
diff --git a/src/audio_core/sink/sink_stream.h b/src/audio_core/sink/sink_stream.h index 38a4b2f51..5fea72ab7 100644 --- a/src/audio_core/sink/sink_stream.h +++ b/src/audio_core/sink/sink_stream.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <atomic> | 7 | #include <atomic> |
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | #include <mutex> | ||
| 9 | #include <span> | 10 | #include <span> |
| 10 | #include <vector> | 11 | #include <vector> |
| 11 | 12 | ||
| @@ -240,8 +241,8 @@ private: | |||
| 240 | f32 system_volume{1.0f}; | 241 | f32 system_volume{1.0f}; |
| 241 | /// Set via IAudioDevice service calls | 242 | /// Set via IAudioDevice service calls |
| 242 | f32 device_volume{1.0f}; | 243 | f32 device_volume{1.0f}; |
| 243 | /// True if coretiming has been stalled | 244 | std::mutex stall_guard; |
| 244 | bool stalled{false}; | 245 | std::unique_lock<std::mutex> stalled_lock; |
| 245 | }; | 246 | }; |
| 246 | 247 | ||
| 247 | using SinkStreamPtr = std::unique_ptr<SinkStream>; | 248 | using SinkStreamPtr = std::unique_ptr<SinkStream>; |
diff --git a/src/core/core.cpp b/src/core/core.cpp index d8934be52..94d4e2212 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -189,7 +189,7 @@ struct System::Impl { | |||
| 189 | 189 | ||
| 190 | kernel.Suspend(false); | 190 | kernel.Suspend(false); |
| 191 | core_timing.SyncPause(false); | 191 | core_timing.SyncPause(false); |
| 192 | is_paused = false; | 192 | is_paused.store(false, std::memory_order_relaxed); |
| 193 | 193 | ||
| 194 | return status; | 194 | return status; |
| 195 | } | 195 | } |
| @@ -200,14 +200,13 @@ struct System::Impl { | |||
| 200 | 200 | ||
| 201 | core_timing.SyncPause(true); | 201 | core_timing.SyncPause(true); |
| 202 | kernel.Suspend(true); | 202 | kernel.Suspend(true); |
| 203 | is_paused = true; | 203 | is_paused.store(true, std::memory_order_relaxed); |
| 204 | 204 | ||
| 205 | return status; | 205 | return status; |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | bool IsPaused() const { | 208 | bool IsPaused() const { |
| 209 | std::unique_lock lk(suspend_guard); | 209 | return is_paused.load(std::memory_order_relaxed); |
| 210 | return is_paused; | ||
| 211 | } | 210 | } |
| 212 | 211 | ||
| 213 | std::unique_lock<std::mutex> StallProcesses() { | 212 | std::unique_lock<std::mutex> StallProcesses() { |
| @@ -218,7 +217,7 @@ struct System::Impl { | |||
| 218 | } | 217 | } |
| 219 | 218 | ||
| 220 | void UnstallProcesses() { | 219 | void UnstallProcesses() { |
| 221 | if (!is_paused) { | 220 | if (!IsPaused()) { |
| 222 | core_timing.SyncPause(false); | 221 | core_timing.SyncPause(false); |
| 223 | kernel.Suspend(false); | 222 | kernel.Suspend(false); |
| 224 | } | 223 | } |
| @@ -465,7 +464,7 @@ struct System::Impl { | |||
| 465 | } | 464 | } |
| 466 | 465 | ||
| 467 | mutable std::mutex suspend_guard; | 466 | mutable std::mutex suspend_guard; |
| 468 | bool is_paused{}; | 467 | std::atomic_bool is_paused{}; |
| 469 | std::atomic<bool> is_shutting_down{}; | 468 | std::atomic<bool> is_shutting_down{}; |
| 470 | 469 | ||
| 471 | Timing::CoreTiming core_timing; | 470 | Timing::CoreTiming core_timing; |