summaryrefslogtreecommitdiff
path: root/Runtime/Threading/JobSystem.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-26 09:48:47 +0800
committerchai <chaifix@163.com>2021-10-26 09:48:47 +0800
commitef7aedf5f272c52247d8ee9522d7b2896d21af63 (patch)
treec1259190bd51ed1225017507cd01612cc5a73a8c /Runtime/Threading/JobSystem.cpp
parente7c760c884d90ef22fe46508b18081fe6e0f9291 (diff)
*misc
Diffstat (limited to 'Runtime/Threading/JobSystem.cpp')
-rw-r--r--Runtime/Threading/JobSystem.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/Runtime/Threading/JobSystem.cpp b/Runtime/Threading/JobSystem.cpp
index a026300..1c62123 100644
--- a/Runtime/Threading/JobSystem.cpp
+++ b/Runtime/Threading/JobSystem.cpp
@@ -1,6 +1,8 @@
#include "JobSystem.h"
+#include "Runtime/Debug/Log.h"
JobSystem::JobSystem()
+ : m_Initialized(false)
{
}
@@ -12,15 +14,26 @@ JobSystem::~JobSystem()
void JobSystem::Initilize(int workThreadCount)
{
+ if (m_Initialized)
+ {
+ log_error("JobSystem has already initialized.");
+ return;
+ }
+
if (workThreadCount <= 0)
return;
+ m_ThreadCount = workThreadCount;
+ m_Cur = 0;
+
for (int i = 0; i < workThreadCount; ++i)
{
WorkThread* thread = new WorkThread();
thread->Resume();
m_Threads.push_back(thread);
}
+
+ m_Initialized = true;
}
void JobSystem::Dispatch(void* param)
@@ -39,5 +52,5 @@ void JobSystem::AddJobAtEnd(Job* job)
WorkThread* JobSystem::SelectThread()
{
- return m_Threads[0];
+ return m_Threads[(++m_Cur)% m_ThreadCount];
} \ No newline at end of file