VERY experimental Nintendo Switch 2 emulator
C++
[qt_common, core, audio] remove duplicate string literal definitions, inline SystemManager::threadfunc, increase latency of audio shutdown (#3030)
lizzied1ac5b2e5041
diff --git a/src/audio_core/adsp/apps/audio_renderer/audio_renderer.cpp b/src/audio_core/adsp/apps/audio_renderer/audio_renderer.cppindex b874f87ae6..238a9c863a 100644--- a/src/audio_core/adsp/apps/audio_renderer/audio_renderer.cpp+++ b/src/audio_core/adsp/apps/audio_renderer/audio_renderer.cpp@@ -130,16 +130,14 @@ void AudioRenderer::CreateSinkStreams() {}void AudioRenderer::Main(std::stop_token stop_token) {- static constexpr char name[]{"DSP_AudioRenderer_Main"};- Common::SetCurrentThreadName(name);+ Common::SetCurrentThreadName("DSP_AudioRenderer_Main");Common::SetCurrentThreadPriority(Common::ThreadPriority::High);// TODO: Create buffer map/unmap thread + mailbox// TODO: Create gMix devices, initialize them hereif (mailbox.Receive(Direction::DSP) != Message::InitializeOK) {- LOG_ERROR(Service_Audio,- "ADSP Audio Renderer -- Failed to receive initialize message from host!");+ LOG_ERROR(Service_Audio, "ADSP Audio Renderer -- Failed to receive initialize message from host!");return;}@@ -156,8 +154,8 @@ void AudioRenderer::Main(std::stop_token stop_token) {return;case Message::Render: {- if (system.IsShuttingDown()) [[unlikely]] {- std::this_thread::sleep_for(std::chrono::milliseconds(5));+ if (system.IsShuttingDown()) {+ std::this_thread::sleep_for(std::chrono::milliseconds(200));mailbox.Send(Direction::Host, Message::RenderResponse);continue;}@@ -175,8 +173,8 @@ void AudioRenderer::Main(std::stop_token stop_token) {// this is a new command list, initialize it.if (command_buffer.remaining_command_count == 0) {command_list_processor.Initialize(system, *command_buffer.process,- command_buffer.buffer,- command_buffer.size, streams[index]);+ command_buffer.buffer,+ command_buffer.size, streams[index]);}if (command_buffer.reset_buffer && !buffers_reset[index]) {@@ -213,13 +211,10 @@ void AudioRenderer::Main(std::stop_token stop_token) {command_buffer.render_time_taken_us = end_time - start_time;}}-mailbox.Send(Direction::Host, Message::RenderResponse);} break;-default:- LOG_WARNING(Service_Audio,- "ADSP AudioRenderer received an invalid message, msg={:02X}!", msg);+ LOG_WARNING(Service_Audio, "ADSP AudioRenderer received an invalid message, msg={:02X}!", msg);break;}}diff --git a/src/audio_core/renderer/system_manager.cpp b/src/audio_core/renderer/system_manager.cppindex 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::Rendererdiff --git a/src/audio_core/renderer/system_manager.h b/src/audio_core/renderer/system_manager.hindex 62e8e5f159..ac66e033d9 100644--- a/src/audio_core/renderer/system_manager.h+++ b/src/audio_core/renderer/system_manager.h@@ -1,3 +1,6 @@+// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project+// SPDX-License-Identifier: GPL-3.0-or-later+// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project// SPDX-License-Identifier: GPL-2.0-or-later@@ -66,11 +69,6 @@ public:bool Remove(System& system);private:- /**- * Main thread responsible for command generation.- */- void ThreadFunc(std::stop_token stop_token);-/// Core systemCore::System& core;/// List of pointers to managed systemsdiff --git a/src/core/core_timing.cpp b/src/core/core_timing.cppindex 1c0a2d7bca..c53f9b3e44 100644--- a/src/core/core_timing.cpp+++ b/src/core/core_timing.cpp@@ -54,8 +54,7 @@ CoreTiming::~CoreTiming() {}void CoreTiming::ThreadEntry(CoreTiming& instance) {- static constexpr char name[] = "HostTiming";- Common::SetCurrentThreadName(name);+ Common::SetCurrentThreadName("HostTiming");Common::SetCurrentThreadPriority(Common::ThreadPriority::High);instance.on_thread_init();instance.ThreadLoop();diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex 1cc060827d..1889ed9938 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -1056,21 +1056,20 @@ static std::jthread RunHostThreadFunc(KernelCore& kernel, KProcess* process,// Register the thread.KThread::Register(kernel, thread);- return std::jthread(- [&kernel, thread, thread_name_{std::move(thread_name)}, func_{std::move(func)}] {- // Set the thread name.- Common::SetCurrentThreadName(thread_name_.c_str());+ return std::jthread([&kernel, thread, thread_name_{std::move(thread_name)}, func_{std::move(func)}] {+ // Set the thread name.+ Common::SetCurrentThreadName(thread_name_.c_str());- // Set the thread as current.- kernel.RegisterHostThread(thread);+ // Set the thread as current.+ kernel.RegisterHostThread(thread);- // Run the callback.- func_();+ // Run the callback.+ func_();- // Close the thread.- // This will free the process if it is the last reference.- thread->Close();- });+ // Close the thread.+ // This will free the process if it is the last reference.+ thread->Close();+ });}std::jthread KernelCore::RunOnHostCoreProcess(std::string&& process_name,diff --git a/src/qt_common/discord/discord_impl.cpp b/src/qt_common/discord/discord_impl.cppindex ad6056be65..c6af6145ca 100644--- a/src/qt_common/discord/discord_impl.cpp+++ b/src/qt_common/discord/discord_impl.cpp@@ -69,11 +69,11 @@ std::string DiscordImpl::GetGameString(const std::string& title) {return icon_name;}+static constexpr char DEFAULT_DISCORD_TEXT[] = "Eden is an emulator for the Nintendo Switch";+static constexpr char DEFAULT_DISCORD_IMAGE[] = "https://git.eden-emu.dev/eden-emu/eden/raw/branch/master/dist/qt_themes/default/icons/256x256/eden.png";+void DiscordImpl::UpdateGameStatus(bool use_default) {- const std::string default_text = "Eden is an emulator for the Nintendo Switch";- const std::string default_image = "https://git.eden-emu.dev/eden-emu/eden/raw/branch/master/"- "dist/qt_themes/default/icons/256x256/eden.png";- const std::string url = use_default ? default_image : game_url;+ const std::string url = use_default ? std::string{DEFAULT_DISCORD_IMAGE} : game_url;s64 start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();@@ -81,8 +81,8 @@ void DiscordImpl::UpdateGameStatus(bool use_default) {presence.largeImageKey = url.c_str();presence.largeImageText = game_title.c_str();- presence.smallImageKey = default_image.c_str();- presence.smallImageText = default_text.c_str();+ presence.smallImageKey = DEFAULT_DISCORD_IMAGE;+ presence.smallImageText = DEFAULT_DISCORD_TEXT;presence.state = game_title.c_str();presence.details = "Currently in game";presence.startTimestamp = start_time;@@ -90,10 +90,6 @@ void DiscordImpl::UpdateGameStatus(bool use_default) {}void DiscordImpl::Update() {- const std::string default_text = "Eden is an emulator for the Nintendo Switch";- const std::string default_image = "https://git.eden-emu.dev/eden-emu/eden/raw/branch/master/"- "dist/qt_themes/default/icons/256x256/eden.png";-if (system.IsPoweredOn()) {system.GetAppLoader().ReadTitle(game_title);@@ -123,13 +119,10 @@ void DiscordImpl::Update() {return;}- s64 start_time = std::chrono::duration_cast<std::chrono::seconds>(- std::chrono::system_clock::now().time_since_epoch())- .count();-+ s64 start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();DiscordRichPresence presence{};- presence.largeImageKey = default_image.c_str();- presence.largeImageText = default_text.c_str();+ presence.largeImageKey = DEFAULT_DISCORD_IMAGE;+ presence.largeImageText = DEFAULT_DISCORD_TEXT;presence.details = "Currently not in game";presence.startTimestamp = start_time;Discord_UpdatePresence(&presence);diff --git a/src/video_core/fence_manager.h b/src/video_core/fence_manager.hindex 0f927159ba..b77235f438 100644--- a/src/video_core/fence_manager.h+++ b/src/video_core/fence_manager.h@@ -227,9 +227,7 @@ private:}void ReleaseThreadFunc(std::stop_token stop_token) {- std::string name = "GPUFencingThread";-- Common::SetCurrentThreadName(name.c_str());+ Common::SetCurrentThreadName("GPUFencingThread");Common::SetCurrentThreadPriority(Common::ThreadPriority::High);TFence current_fence;diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cppindex a5d69821bd..b6cd7d0985 100644--- a/src/yuzu/bootmanager.cpp+++ b/src/yuzu/bootmanager.cpp@@ -71,8 +71,7 @@ EmuThread::EmuThread(Core::System& system) : m_system{system} {}EmuThread::~EmuThread() = default;void EmuThread::run() {- const char* name = "EmuControlThread";- Common::SetCurrentThreadName(name);+ Common::SetCurrentThreadName("EmuControlThread");auto& gpu = m_system.GPU();auto stop_token = m_stop_source.get_token();