summaryrefslogtreecommitdiff
path: root/Runtime/Threading/WorkThread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Threading/WorkThread.cpp')
-rw-r--r--Runtime/Threading/WorkThread.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/Runtime/Threading/WorkThread.cpp b/Runtime/Threading/WorkThread.cpp
new file mode 100644
index 0000000..b3b462a
--- /dev/null
+++ b/Runtime/Threading/WorkThread.cpp
@@ -0,0 +1,48 @@
+#include "Thread.h"
+#include "Runtime/Debug/Log.h"
+
+void WorkThread::Run()
+{
+ while (true)
+ {
+ _lock(m_PendingMutex)
+ {
+ for (auto iter = m_PendingJobs.begin(); iter != m_PendingJobs.end();)
+ {
+ Job* job = *iter;
+ job->Process();
+ if (job->IsFinished())
+ {
+ _lock(m_FinishedMutex) {
+ m_FinishedJobs.push_back(job);
+ }
+ iter = m_PendingJobs.erase(iter);
+ continue;
+ }
+ ++iter;
+ }
+ if (m_PendingJobs.size() == 0)
+ ::Sleep(1);
+ }
+ }
+}
+
+void WorkThread::Dispatch(void* param)
+{
+ _lock(m_FinishedMutex)
+ {
+ for (int i = 0; i < m_FinishedJobs.size(); ++i)
+ {
+ m_FinishedJobs[i]->Dispacth(param);
+ }
+ m_FinishedJobs.clear();
+ }
+}
+
+void WorkThread::AddJobAtEnd(Job* job)
+{
+ _lock(m_PendingMutex)
+ {
+ m_PendingJobs.push_back(job);
+ }
+} \ No newline at end of file