mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 02:32:36 +01:00
Thread.h: Improve thread abort performance
This commit is contained in:
parent
c7586de280
commit
daf43989fc
@ -635,9 +635,11 @@ public:
|
|||||||
// Join thread by thread_state::finished
|
// Join thread by thread_state::finished
|
||||||
named_thread& operator=(thread_state s)
|
named_thread& operator=(thread_state s)
|
||||||
{
|
{
|
||||||
|
bool notify_sync = false;
|
||||||
|
|
||||||
if (s >= thread_state::aborting && thread::m_sync.fetch_op([](u64& v){ return !(v & 3) && (v |= 1); }).second)
|
if (s >= thread_state::aborting && thread::m_sync.fetch_op([](u64& v){ return !(v & 3) && (v |= 1); }).second)
|
||||||
{
|
{
|
||||||
thread::m_sync.notify_one(1);
|
notify_sync = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if constexpr (std::is_assignable_v<Context&, thread_state>)
|
if constexpr (std::is_assignable_v<Context&, thread_state>)
|
||||||
@ -645,6 +647,12 @@ public:
|
|||||||
static_cast<Context&>(*this) = s;
|
static_cast<Context&>(*this) = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (notify_sync)
|
||||||
|
{
|
||||||
|
// Notify after context abortion has been made so all conditions for wake-up be satisfied by the time of notification
|
||||||
|
thread::m_sync.notify_one(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (s == thread_state::finished)
|
if (s == thread_state::finished)
|
||||||
{
|
{
|
||||||
// This participates in emulation stopping, use destruction-alike semantics
|
// This participates in emulation stopping, use destruction-alike semantics
|
||||||
|
@ -881,8 +881,19 @@ void cpu_thread::notify()
|
|||||||
|
|
||||||
cpu_thread& cpu_thread::operator=(thread_state)
|
cpu_thread& cpu_thread::operator=(thread_state)
|
||||||
{
|
{
|
||||||
state += cpu_flag::exit;
|
if (state & cpu_flag::exit)
|
||||||
state.notify_one(cpu_flag::exit);
|
{
|
||||||
|
// Must be notified elsewhere or self-raised
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto old = state.fetch_add(cpu_flag::exit);
|
||||||
|
|
||||||
|
if (old & cpu_flag::wait && old.none_of(cpu_flag::again + cpu_flag::exit))
|
||||||
|
{
|
||||||
|
state.notify_one(cpu_flag::exit);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user