diff options
Diffstat (limited to 'Runtime/Threading/JobSystem.cpp')
-rw-r--r-- | Runtime/Threading/JobSystem.cpp | 15 |
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 |