From be0e4e9879da26b99daf11deb94b1db1e54b83e7 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Fri, 28 Feb 2020 21:52:09 +0300 Subject: [PATCH] Move Progress Dialog Server to named_thread Make it a global variable, but that can be actually destructed at exit. --- rpcs3/Emu/System.cpp | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 5bbf4e48f0..49bf7cc1fb 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -217,20 +217,32 @@ void Emulator::Init() // Initialize patch engine g_fxo->init()->append(fs::get_config_dir() + "/patch.yml"); +} - // Initialize progress dialog server (TODO) - if (g_progr.exchange("") == nullptr) +namespace +{ + struct progress_dialog_server { - std::thread server([]() + void operator()() { - while (true) + while (thread_ctrl::state() != thread_state::aborting) { // Wait for the start condition while (!g_progr_ftotal && !g_progr_ptotal) { + if (thread_ctrl::state() == thread_state::aborting) + { + break; + } + std::this_thread::sleep_for(5ms); } + if (thread_ctrl::state() == thread_state::aborting) + { + break; + } + // Initialize message dialog std::shared_ptr dlg = Emu.GetCallbacks().get_msg_dialog(); if (dlg) @@ -260,7 +272,7 @@ void Emulator::Init() u32 value = 0; // Update progress - while (true) + while (thread_ctrl::state() != thread_state::aborting) { if (ftotal != g_progr_ftotal || fdone != g_progr_fdone || ptotal != g_progr_ptotal || pdone != g_progr_pdone) { @@ -307,6 +319,11 @@ void Emulator::Init() std::this_thread::sleep_for(10ms); } + if (thread_ctrl::state() == thread_state::aborting) + { + break; + } + // Cleanup g_progr_ftotal -= fdone; g_progr_fdone -= fdone; @@ -321,10 +338,10 @@ void Emulator::Init() }); } } - }); + } - server.detach(); - } + static auto constexpr thread_name = "Progress Dialog Server"sv; + }; } const bool Emulator::SetUsr(const std::string& user) @@ -1769,3 +1786,5 @@ void stx::manual_fixed_typemap::destroy_reporter(const char* name, unsigne } Emulator Emu; + +named_thread g_progress_dlg_server;