Improve thread aborting mechanism (#10490)

Call pseudo-virtual operator=(thread_state) of thread context.
This commit is contained in:
Eladash 2021-06-27 11:43:48 +03:00 committed by GitHub
parent 58847fa2ca
commit 0aed00a758
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 44 deletions

View file

@ -812,6 +812,8 @@ bool cpu_thread::check_state() noexcept
void cpu_thread::notify()
{
state.notify_one();
// Downcast to correct type
if (id_type() == 1)
{
@ -827,6 +829,13 @@ void cpu_thread::notify()
}
}
cpu_thread& cpu_thread::operator=(thread_state)
{
state += cpu_flag::exit;
state.notify_one(cpu_flag::exit);
return *this;
}
std::string cpu_thread::get_name() const
{
// Downcast to correct type
@ -1099,29 +1108,6 @@ bool cpu_thread::suspend_work::push(cpu_thread* _this) noexcept
return true;
}
void cpu_thread::stop_all() noexcept
{
if (g_tls_this_thread)
{
// Report unsupported but unnecessary case
sys_log.fatal("cpu_thread::stop_all() has been called from a CPU thread.");
return;
}
else
{
auto on_stop = [](u32, cpu_thread& cpu)
{
cpu.state += cpu_flag::exit;
cpu.state.notify_one(cpu_flag::exit);
};
idm::select<named_thread<ppu_thread>>(on_stop);
idm::select<named_thread<spu_thread>>(on_stop);
}
sys_log.notice("All CPU threads have been signaled.");
}
void cpu_thread::cleanup() noexcept
{
ensure(!s_cpu_counter);