Skip to content

Commit

Permalink
Use threadpool for CreateNewInstancesForPlayers.
Browse files Browse the repository at this point in the history
  • Loading branch information
ratkosrb committed Sep 28, 2024
1 parent 93bb983 commit a9321a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/game/Maps/MapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThreadPool::MySQL<>>();
m_instanceCreationThreads->start<>();
}

MapManager::~MapManager()
Expand Down Expand Up @@ -336,7 +338,10 @@ void MapManager::Update(uint32 diff)
}
}

std::thread instanceCreationThread = std::thread(&MapManager::CreateNewInstancesForPlayers, this);
std::vector<std::function<void()>> instanceCreators;
instanceCreators.emplace_back([this]() {CreateNewInstancesForPlayers();});
std::future<void> instances = m_instanceCreationThreads->processWorkload(std::move(instanceCreators),
ThreadPool::Callable());

i_maxContinentThread = continentsIdx;
i_continentUpdateFinished.store(0);
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/game/Maps/MapManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::ClassLevelLockab

std::unique_ptr<ThreadPool> m_threads;
std::unique_ptr<ThreadPool> m_continentThreads;
std::unique_ptr<ThreadPool> m_instanceCreationThreads;
bool asyncMapUpdating = false;

// Instanced continent zones
Expand Down

0 comments on commit a9321a4

Please sign in to comment.