From ef7aedf5f272c52247d8ee9522d7b2896d21af63 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 26 Oct 2021 09:48:47 +0800 Subject: *misc --- Runtime/Threading/JobSystem.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Runtime/Threading/JobSystem.cpp') 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 -- cgit v1.1-26-g67d0