aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/workthreadpool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore/workthreadpool.cpp')
-rw-r--r--src/zencore/workthreadpool.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/zencore/workthreadpool.cpp b/src/zencore/workthreadpool.cpp
index 3a4b1e6a1..6ff6463dd 100644
--- a/src/zencore/workthreadpool.cpp
+++ b/src/zencore/workthreadpool.cpp
@@ -74,6 +74,7 @@ struct WorkerThreadPool::Impl
{
WaitForThreadpoolWorkCallbacks(m_Work, /* CancelPendingCallbacks */ TRUE);
CloseThreadpoolWork(m_Work);
+ CloseThreadpool(m_ThreadPool);
}
void ScheduleWork(Ref<IWork> Work)
@@ -109,6 +110,7 @@ struct WorkerThreadPool::Impl
m_WorkQueue.pop_front();
}
+ ZEN_TRACE_CPU_FLUSH("AsyncWork");
WorkFromQueue->Execute();
}
};
@@ -150,7 +152,10 @@ struct WorkerThreadPool::Impl
for (std::thread& Thread : m_WorkerThreads)
{
- Thread.join();
+ if (Thread.joinable())
+ {
+ Thread.join();
+ }
}
m_WorkerThreads.clear();
@@ -174,6 +179,7 @@ WorkerThreadPool::Impl::WorkerThreadFunction(ThreadStartInfo Info)
{
try
{
+ ZEN_TRACE_CPU_FLUSH("AsyncWork");
Work->Execute();
}
catch (std::exception& e)
@@ -219,7 +225,17 @@ WorkerThreadPool::ScheduleWork(Ref<IWork> Work)
}
else
{
- Work->Execute();
+ try
+ {
+ ZEN_TRACE_CPU_FLUSH("SyncWork");
+ Work->Execute();
+ }
+ catch (std::exception& e)
+ {
+ Work->m_Exception = std::current_exception();
+
+ ZEN_WARN("Caught exception when executing worker synchronously: {}", e.what());
+ }
}
}