CPUThread fixes, thread_t cleanup

This commit is contained in:
Nekotekina 2015-07-06 22:35:34 +03:00
parent 83321c5be7
commit eafddd9e33
10 changed files with 69 additions and 83 deletions

View file

@ -1307,14 +1307,11 @@ void thread_t::start(std::function<std::string()> name, std::function<void()> fu
}
//ctrl->set_current(false);
vm::reservation_free();
g_thread_count--;
ctrl->joinable = false;
ctrl->join_cv.notify_all();
#if defined(_MSC_VER)
_set_se_translator(old_se_translator);
#endif
@ -1331,39 +1328,16 @@ void thread_t::detach()
// +clear m_thread
const auto ctrl = std::move(m_thread);
cv.notify_all();
{
// lock for reliable notification
std::lock_guard<std::mutex> lock(mutex);
cv.notify_all();
}
ctrl->m_thread.detach();
}
void thread_t::join(std::unique_lock<std::mutex>& lock)
{
if (!m_thread)
{
throw EXCEPTION("Invalid thread");
}
if (g_tls_this_thread == m_thread.get())
{
throw EXCEPTION("Deadlock");
}
// +clear m_thread
const auto ctrl = std::move(m_thread);
cv.notify_all();
// wait for completion
while (ctrl->joinable)
{
CHECK_EMU_STATUS;
ctrl->join_cv.wait_for(lock, std::chrono::milliseconds(1));
}
ctrl->m_thread.join();
}
void thread_t::join()
{
if (!m_thread)
@ -1379,7 +1353,12 @@ void thread_t::join()
// +clear m_thread
const auto ctrl = std::move(m_thread);
cv.notify_all();
{
// lock for reliable notification
std::lock_guard<std::mutex> lock(mutex);
cv.notify_all();
}
ctrl->m_thread.join();
}