diff options
Diffstat (limited to 'Client/Source/Threading/JobSystem.cpp')
-rw-r--r-- | Client/Source/Threading/JobSystem.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Client/Source/Threading/JobSystem.cpp b/Client/Source/Threading/JobSystem.cpp new file mode 100644 index 0000000..378d74f --- /dev/null +++ b/Client/Source/Threading/JobSystem.cpp @@ -0,0 +1,56 @@ +#include "JobSystem.h" +#include "../Debug/Log.h" + +JobSystem::JobSystem() + : m_Initialized(false) +{ + +} + +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) +{ + for (int i = 0; i < m_Threads.size(); ++i) + { + m_Threads[i]->Dispatch(param); + } +} + +void JobSystem::AddJobAtEnd(Job* job) +{ + WorkThread* thread = SelectThread(); + thread->AddJobAtEnd(job); +} + +WorkThread* JobSystem::SelectThread() +{ + return m_Threads[(++m_Cur)% m_ThreadCount]; +}
\ No newline at end of file |