diff --git a/src/engine/shared/jobs.cpp b/src/engine/shared/jobs.cpp index 387ab2144..0fe558fda 100644 --- a/src/engine/shared/jobs.cpp +++ b/src/engine/shared/jobs.cpp @@ -19,7 +19,6 @@ int IJob::Status() CJobPool::CJobPool() { // empty the pool - m_NumThreads = 0; m_Shutdown = false; m_Lock = lock_create(); sphore_init(&m_Semaphore); @@ -69,21 +68,19 @@ void CJobPool::WorkerThread(void *pUser) void CJobPool::Init(int NumThreads) { // start threads - m_NumThreads = NumThreads > MAX_THREADS ? MAX_THREADS : NumThreads; + m_vpThreads.reserve(NumThreads); for(int i = 0; i < NumThreads; i++) - m_apThreads[i] = thread_init(WorkerThread, this, "CJobPool worker"); + m_vpThreads.push_back(thread_init(WorkerThread, this, "CJobPool worker")); } void CJobPool::Destroy() { m_Shutdown = true; - for(int i = 0; i < m_NumThreads; i++) + for(size_t i = 0; i < m_vpThreads.size(); i++) sphore_signal(&m_Semaphore); - for(int i = 0; i < m_NumThreads; i++) - { - if(m_apThreads[i]) - thread_wait(m_apThreads[i]); - } + for(void *pThread : m_vpThreads) + thread_wait(pThread); + m_vpThreads.clear(); lock_destroy(m_Lock); sphore_destroy(&m_Semaphore); } diff --git a/src/engine/shared/jobs.h b/src/engine/shared/jobs.h index fa99166f9..2a24efbdc 100644 --- a/src/engine/shared/jobs.h +++ b/src/engine/shared/jobs.h @@ -7,6 +7,7 @@ #include #include +#include class CJobPool; @@ -37,12 +38,7 @@ public: class CJobPool { - enum - { - MAX_THREADS = 32 - }; - int m_NumThreads; - void *m_apThreads[MAX_THREADS]; + std::vector m_vpThreads; std::atomic m_Shutdown; LOCK m_Lock;