diff --git a/src/game/Maps/MapManager.cpp b/src/game/Maps/MapManager.cpp index d8a46537b02..0695fc84754 100644 --- a/src/game/Maps/MapManager.cpp +++ b/src/game/Maps/MapManager.cpp @@ -42,10 +42,12 @@ MapManager::MapManager() : i_gridCleanUpDelay(sWorld.getConfig(CONFIG_UINT32_INTERVAL_GRIDCLEAN)), i_MaxInstanceId(RESERVED_INSTANCES_LAST), - m_threads(new ThreadPool(sWorld.getConfig(CONFIG_UINT32_MAPUPDATE_INSTANCED_UPDATE_THREADS))) + m_threads(new ThreadPool(sWorld.getConfig(CONFIG_UINT32_MAPUPDATE_INSTANCED_UPDATE_THREADS))), + m_instanceCreationThreads(new ThreadPool(1)) { i_timer.SetInterval(sWorld.getConfig(CONFIG_UINT32_INTERVAL_MAPUPDATE)); m_threads->start>(); + m_instanceCreationThreads->start<>(); } MapManager::~MapManager() @@ -336,7 +338,10 @@ void MapManager::Update(uint32 diff) } } - std::thread instanceCreationThread = std::thread(&MapManager::CreateNewInstancesForPlayers, this); + std::vector> instanceCreators; + instanceCreators.emplace_back([this]() {CreateNewInstancesForPlayers();}); + std::future instances = m_instanceCreationThreads->processWorkload(std::move(instanceCreators), + ThreadPool::Callable()); i_maxContinentThread = continentsIdx; i_continentUpdateFinished.store(0); @@ -367,8 +372,8 @@ void MapManager::Update(uint32 diff) SwitchPlayersInstances(); asyncMapUpdating = false; - if (instanceCreationThread.joinable()) - instanceCreationThread.join(); + if (instances.valid()) + instances.wait(); // Execute far teleports after all map updates have finished ExecuteDelayedPlayerTeleports(); diff --git a/src/game/Maps/MapManager.h b/src/game/Maps/MapManager.h index 54f526cffc0..e3a4aa1f9e8 100644 --- a/src/game/Maps/MapManager.h +++ b/src/game/Maps/MapManager.h @@ -225,6 +225,7 @@ class MapManager : public MaNGOS::Singleton m_threads; std::unique_ptr m_continentThreads; + std::unique_ptr m_instanceCreationThreads; bool asyncMapUpdating = false; // Instanced continent zones