From d82b2b1a6712df685b989911e3e519809935de03 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 8 Oct 2022 20:08:29 +0200 Subject: Core/Threading: Create ThreadPool class --- src/server/worldserver/Main.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/server/worldserver/Main.cpp') diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 69b226a319a..9bf26b84ef5 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -49,6 +49,7 @@ #include "SecretMgr.h" #include "SharedDefines.h" #include "TCSoap.h" +#include "ThreadPool.h" #include "World.h" #include "WorldSocket.h" #include "WorldSocketMgr.h" @@ -241,20 +242,13 @@ extern int main(int argc, char** argv) // Start the Boost based thread pool int numThreads = sConfigMgr->GetIntDefault("ThreadPool", 1); - std::shared_ptr> threadPool(new std::vector(), [ioContext](std::vector* del) - { - ioContext->stop(); - for (std::thread& thr : *del) - thr.join(); - - delete del; - }); - if (numThreads < 1) numThreads = 1; + std::shared_ptr threadPool = std::make_shared(numThreads); + for (int i = 0; i < numThreads; ++i) - threadPool->push_back(std::thread([ioContext]() { ioContext->run(); })); + threadPool->PostWork([ioContext]() { ioContext->run(); }); // Set process priority according to configuration settings SetProcessPriority("server.worldserver", sConfigMgr->GetIntDefault(CONFIG_PROCESSOR_AFFINITY, 0), sConfigMgr->GetBoolDefault(CONFIG_HIGH_PRIORITY, false)); @@ -390,6 +384,8 @@ extern int main(int argc, char** argv) WorldUpdateLoop(); // Shutdown starts here + ioContext->stop(); + threadPool.reset(); sLog->SetSynchronous(); -- cgit v1.2.3