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

@ -35,8 +35,6 @@ enum class thread_state : u32
mask = 3
};
class need_wakeup {};
template <class Context>
class named_thread;
@ -616,14 +614,14 @@ public:
// Join thread by thread_state::finished
named_thread& operator=(thread_state s)
{
if constexpr (std::is_assignable_v<Context&, thread_state>)
{
static_cast<Context&>(*this) = s;
}
if (s >= thread_state::aborting && thread::m_sync.fetch_op([](u64& v){ return !(v & 3) && (v |= 1); }).second)
{
thread::m_sync.notify_one(1);
if constexpr (std::is_base_of_v<need_wakeup, Context>)
{
this->wake_up();
}
}
if (s == thread_state::finished)