Simplify thread_base::join()
Use waitable atomics
This commit is contained in:
+4
-11
@@ -1766,8 +1766,7 @@ bool thread_base::finalize(int) noexcept
|
|||||||
const bool result = m_state.exchange(thread_state::finished) == thread_state::detached;
|
const bool result = m_state.exchange(thread_state::finished) == thread_state::detached;
|
||||||
|
|
||||||
// Signal waiting threads
|
// Signal waiting threads
|
||||||
m_mutex.lock_unlock();
|
m_state.notify_all();
|
||||||
m_jcv.notify_all();
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1845,16 +1844,10 @@ thread_base::~thread_base()
|
|||||||
|
|
||||||
void thread_base::join() const
|
void thread_base::join() const
|
||||||
{
|
{
|
||||||
if (m_state == thread_state::finished)
|
for (auto state = m_state.load(); state != thread_state::finished;)
|
||||||
{
|
{
|
||||||
return;
|
m_state.wait(state);
|
||||||
}
|
state = m_state;
|
||||||
|
|
||||||
std::unique_lock lock(m_mutex);
|
|
||||||
|
|
||||||
while (m_state != thread_state::finished)
|
|
||||||
{
|
|
||||||
m_jcv.wait(lock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,9 +124,6 @@ class thread_base
|
|||||||
// Thread flags
|
// Thread flags
|
||||||
atomic_t<u32> m_signal{0};
|
atomic_t<u32> m_signal{0};
|
||||||
|
|
||||||
// Thread joining condition variable
|
|
||||||
mutable cond_variable m_jcv;
|
|
||||||
|
|
||||||
// Thread state
|
// Thread state
|
||||||
atomic_t<thread_state> m_state = thread_state::created;
|
atomic_t<thread_state> m_state = thread_state::created;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user