summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/audio_core/renderer/adsp/audio_renderer.cpp8
-rw-r--r--src/audio_core/renderer/adsp/audio_renderer.h4
-rw-r--r--src/audio_core/sink/sink_stream.cpp5
-rw-r--r--src/audio_core/sink/sink_stream.h5
4 files changed, 12 insertions, 10 deletions
diff --git a/src/audio_core/renderer/adsp/audio_renderer.cpp b/src/audio_core/renderer/adsp/audio_renderer.cpp
index 1cbeed302..8bc39f9f9 100644
--- a/src/audio_core/renderer/adsp/audio_renderer.cpp
+++ b/src/audio_core/renderer/adsp/audio_renderer.cpp
@@ -105,7 +105,7 @@ void AudioRenderer::Start(AudioRenderer_Mailbox* mailbox_) {
105 } 105 }
106 106
107 mailbox = mailbox_; 107 mailbox = mailbox_;
108 thread = std::thread(&AudioRenderer::ThreadFunc, this); 108 thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(stop_token); });
109 running = true; 109 running = true;
110} 110}
111 111
@@ -131,7 +131,7 @@ void AudioRenderer::CreateSinkStreams() {
131 } 131 }
132} 132}
133 133
134void AudioRenderer::ThreadFunc() { 134void AudioRenderer::ThreadFunc(std::stop_token stop_token) {
135 static constexpr char name[]{"AudioRenderer"}; 135 static constexpr char name[]{"AudioRenderer"};
136 MicroProfileOnThreadCreate(name); 136 MicroProfileOnThreadCreate(name);
137 Common::SetCurrentThreadName(name); 137 Common::SetCurrentThreadName(name);
@@ -146,7 +146,7 @@ void AudioRenderer::ThreadFunc() {
146 146
147 constexpr u64 max_process_time{2'304'000ULL}; 147 constexpr u64 max_process_time{2'304'000ULL};
148 148
149 while (true) { 149 while (!stop_token.stop_requested()) {
150 auto message{mailbox->ADSPWaitMessage()}; 150 auto message{mailbox->ADSPWaitMessage()};
151 switch (message) { 151 switch (message) {
152 case RenderMessage::AudioRenderer_Shutdown: 152 case RenderMessage::AudioRenderer_Shutdown:
@@ -194,7 +194,7 @@ void AudioRenderer::ThreadFunc() {
194 max_time = std::min(command_buffer.time_limit, max_time); 194 max_time = std::min(command_buffer.time_limit, max_time);
195 command_list_processor.SetProcessTimeMax(max_time); 195 command_list_processor.SetProcessTimeMax(max_time);
196 196
197 streams[index]->WaitFreeSpace(); 197 streams[index]->WaitFreeSpace(stop_token);
198 198
199 // Process the command list 199 // Process the command list
200 { 200 {
diff --git a/src/audio_core/renderer/adsp/audio_renderer.h b/src/audio_core/renderer/adsp/audio_renderer.h
index 85ce6a269..88e558183 100644
--- a/src/audio_core/renderer/adsp/audio_renderer.h
+++ b/src/audio_core/renderer/adsp/audio_renderer.h
@@ -177,7 +177,7 @@ private:
177 /** 177 /**
178 * Main AudioRenderer thread, responsible for processing the command lists. 178 * Main AudioRenderer thread, responsible for processing the command lists.
179 */ 179 */
180 void ThreadFunc(); 180 void ThreadFunc(std::stop_token stop_token);
181 181
182 /** 182 /**
183 * Creates the streams which will receive the processed samples. 183 * Creates the streams which will receive the processed samples.
@@ -187,7 +187,7 @@ private:
187 /// Core system 187 /// Core system
188 Core::System& system; 188 Core::System& system;
189 /// Main thread 189 /// Main thread
190 std::thread thread{}; 190 std::jthread thread{};
191 /// The current state 191 /// The current state
192 std::atomic<bool> running{}; 192 std::atomic<bool> running{};
193 /// The active mailbox 193 /// The active mailbox
diff --git a/src/audio_core/sink/sink_stream.cpp b/src/audio_core/sink/sink_stream.cpp
index 2331aaff9..f44fedfd5 100644
--- a/src/audio_core/sink/sink_stream.cpp
+++ b/src/audio_core/sink/sink_stream.cpp
@@ -269,12 +269,13 @@ u64 SinkStream::GetExpectedPlayedSampleCount() {
269 return std::min<u64>(exp_played_sample_count, max_played_sample_count) + TargetSampleCount * 3; 269 return std::min<u64>(exp_played_sample_count, max_played_sample_count) + TargetSampleCount * 3;
270} 270}
271 271
272void SinkStream::WaitFreeSpace() { 272void SinkStream::WaitFreeSpace(std::stop_token stop_token) {
273 std::unique_lock lk{release_mutex}; 273 std::unique_lock lk{release_mutex};
274 release_cv.wait_for(lk, std::chrono::milliseconds(5), 274 release_cv.wait_for(lk, std::chrono::milliseconds(5),
275 [this]() { return queued_buffers < max_queue_size; }); 275 [this]() { return queued_buffers < max_queue_size; });
276 if (queued_buffers > max_queue_size + 3) { 276 if (queued_buffers > max_queue_size + 3) {
277 release_cv.wait(lk, [this]() { return queued_buffers < max_queue_size; }); 277 Common::CondvarWait(release_cv, lk, stop_token,
278 [this] { return queued_buffers < max_queue_size; });
278 } 279 }
279} 280}
280 281
diff --git a/src/audio_core/sink/sink_stream.h b/src/audio_core/sink/sink_stream.h
index 21b5b40a1..41cbadc9c 100644
--- a/src/audio_core/sink/sink_stream.h
+++ b/src/audio_core/sink/sink_stream.h
@@ -13,6 +13,7 @@
13 13
14#include "audio_core/common/common.h" 14#include "audio_core/common/common.h"
15#include "common/common_types.h" 15#include "common/common_types.h"
16#include "common/polyfill_thread.h"
16#include "common/reader_writer_queue.h" 17#include "common/reader_writer_queue.h"
17#include "common/ring_buffer.h" 18#include "common/ring_buffer.h"
18#include "common/thread.h" 19#include "common/thread.h"
@@ -210,7 +211,7 @@ public:
210 /** 211 /**
211 * Waits for free space in the sample ring buffer 212 * Waits for free space in the sample ring buffer
212 */ 213 */
213 void WaitFreeSpace(); 214 void WaitFreeSpace(std::stop_token stop_token);
214 215
215protected: 216protected:
216 /// Core system 217 /// Core system
@@ -252,7 +253,7 @@ private:
252 /// Set via IAudioDevice service calls 253 /// Set via IAudioDevice service calls
253 f32 device_volume{1.0f}; 254 f32 device_volume{1.0f};
254 /// Signalled when ring buffer entries are consumed 255 /// Signalled when ring buffer entries are consumed
255 std::condition_variable release_cv; 256 std::condition_variable_any release_cv;
256 std::mutex release_mutex; 257 std::mutex release_mutex;
257}; 258};
258 259