aboutsummaryrefslogtreecommitdiff
path: root/src/audio_core/renderer/system_manager.cpp
diff options
context:
space:
mode:
authorlizzie <lizzie@eden-emu.dev>2025-11-17 22:37:45 +0100
committercrueter <crueter@eden-emu.dev>2025-11-17 22:37:45 +0100
commitd1ac5b2e5041447652284ea523f98d7291190876 (patch)
tree79e4dd84c41150e5924d38af7635620b2a6c75df /src/audio_core/renderer/system_manager.cpp
parentc160d6b752e6cfad0353e73a398b246e878a647a (diff)
[qt_common, core, audio] remove duplicate string literal definitions, inline SystemManager::threadfunc, increase latency of audio shutdown (#3030)
Very small code cleanup, also remove `[[unlikely]]` because it doesn't matter + increase latency of audio render when shutting down Signed-off-by: lizzie lizzie@eden-emu.dev Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3030 Reviewed-by: Caio Oliveira <caiooliveirafarias0@gmail.com> Reviewed-by: crueter <crueter@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
Diffstat (limited to 'src/audio_core/renderer/system_manager.cpp')
-rw-r--r--src/audio_core/renderer/system_manager.cpp56
1 files changed, 21 insertions, 35 deletions
diff --git a/src/audio_core/renderer/system_manager.cpp b/src/audio_core/renderer/system_manager.cpp
index 8146cb142c..d2c924fdf2 100644
--- a/src/audio_core/renderer/system_manager.cpp
+++ b/src/audio_core/renderer/system_manager.cpp
@@ -26,73 +26,59 @@ void SystemManager::InitializeUnsafe() {
if (!active) {
active = true;
audio_renderer.Start();
- thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(stop_token); });
+ thread = std::jthread([this](std::stop_token stop_token) {
+ Common::SetCurrentThreadName("AudioRenderSystemManager");
+ Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
+ while (active && !stop_token.stop_requested()) {
+ {
+ std::scoped_lock l{mutex1};
+ for (auto system : systems)
+ system->SendCommandToDsp();
+ }
+ audio_renderer.Signal();
+ audio_renderer.Wait();
+ }
+ });
}
}
void SystemManager::Stop() {
- if (!active) {
- return;
+ if (active) {
+ active = false;
+ thread.request_stop();
+ thread.join();
+ audio_renderer.Stop();
}
- active = false;
- thread.request_stop();
- thread.join();
- audio_renderer.Stop();
}
bool SystemManager::Add(System& system_) {
std::scoped_lock l2{mutex2};
-
if (systems.size() + 1 > MaxRendererSessions) {
LOG_ERROR(Service_Audio, "Maximum AudioRenderer Systems active, cannot add more!");
return false;
}
-
{
std::scoped_lock l{mutex1};
- if (systems.empty()) {
+ if (systems.empty())
InitializeUnsafe();
- }
}
-
systems.push_back(&system_);
return true;
}
bool SystemManager::Remove(System& system_) {
std::scoped_lock l2{mutex2};
-
{
std::scoped_lock l{mutex1};
if (systems.remove(&system_) == 0) {
- LOG_ERROR(Service_Audio,
- "Failed to remove a render system, it was not found in the list!");
+ LOG_ERROR(Service_Audio, "Failed to remove a render system, it was not found in the list!");
return false;
}
}
- if (systems.empty()) {
+ if (systems.empty())
Stop();
- }
return true;
}
-void SystemManager::ThreadFunc(std::stop_token stop_token) {
- static constexpr char name[]{"AudioRenderSystemManager"};
- Common::SetCurrentThreadName(name);
- Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
- while (active && !stop_token.stop_requested()) {
- {
- std::scoped_lock l{mutex1};
-
- for (auto system : systems) {
- system->SendCommandToDsp();
- }
- }
-
- audio_renderer.Signal();
- audio_renderer.Wait();
- }
-}
-
} // namespace AudioCore::Renderer