Improve emulation stopping speed

Split phases of signalling threads and joining them.
This commit is contained in:
Eladash 2021-06-05 22:15:15 +03:00 committed by Ivan
parent 2169e8d935
commit 76bf720adf
6 changed files with 109 additions and 39 deletions

View file

@ -1543,6 +1543,35 @@ void Emulator::Stop(bool restart)
}
cpu_thread::stop_all();
using fxo_t = std::remove_pointer_t<decltype(g_fxo)>;
// Signal threads
for (const auto& type : fxo_t::view_typelist())
{
if (type.stop)
{
if (auto data = g_fxo->try_get(type))
{
type.stop(data, thread_state::aborting);
}
}
}
// Join threads
for (const auto& type : fxo_t::view_typelist())
{
if (type.stop)
{
if (auto data = g_fxo->try_get(type))
{
type.stop(data, thread_state::finished);
}
}
}
cpu_thread::cleanup();
g_fxo->reset();
sys_log.notice("All threads have been stopped.");