Thread.h: Improve thread abort performance

This commit is contained in:
Eladash 2022-08-25 12:12:29 +03:00 committed by kd-11
parent c7586de280
commit daf43989fc
2 changed files with 22 additions and 3 deletions

View file

@ -635,9 +635,11 @@ public:
// Join thread by thread_state::finished
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)
{
thread::m_sync.notify_one(1);
notify_sync = true;
}
if constexpr (std::is_assignable_v<Context&, thread_state>)
@ -645,6 +647,12 @@ public:
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)
{
// This participates in emulation stopping, use destruction-alike semantics