Replacing ACE based multi threading with PCQ

This commit is contained in:
leak
2014-07-14 22:51:13 +02:00
parent fe5d38ae7d
commit ecde28d1c1
6 changed files with 62 additions and 37 deletions
@@ -18,7 +18,6 @@
#include <iostream>
#include <iomanip>
#include <mutex>
#include <string>
#include <sstream>
#include "VMapManager2.h"
@@ -47,7 +47,7 @@ public:
_condition.notify_one();
}
bool Empty() const
bool Empty()
{
std::lock_guard<std::mutex> lock(_queueLock);
+2
View File
@@ -22,6 +22,7 @@ set(mmap_gen_Includes
${CMAKE_SOURCE_DIR}/dep/recastnavigation/Detour/Include
${CMAKE_SOURCE_DIR}/src/server/shared
${CMAKE_SOURCE_DIR}/src/server/shared/Utilities
${CMAKE_SOURCE_DIR}/src/server/shared/Threading
${CMAKE_SOURCE_DIR}/src/server/game/Conditions
${CMAKE_SOURCE_DIR}/src/server/collision
${CMAKE_SOURCE_DIR}/src/server/collision/Management
@@ -47,6 +48,7 @@ target_link_libraries(mmaps_generator
Detour
${BZIP2_LIBRARIES}
${ZLIB_LIBRARIES}
${Boost_LIBRARIES}
)
if( UNIX )
+50 -33
View File
@@ -165,42 +165,59 @@ namespace MMAP
}
/**************************************************************************/
void MapBuilder::WorkerThread()
{
while (1)
{
uint32 mapId;
_queue.WaitAndPop(mapId);
if (_cancelationToken)
return;
buildMap(mapId);
}
}
void MapBuilder::buildAllMaps(int threads)
{
for (size_t i = 0; i < threads; ++i)
{
_workerThreads.push_back(std::thread(&MapBuilder::WorkerThread, this));
}
// TODO fix that shit
// std::vector<BuilderThread*> _threads;
//
// BuilderThreadPool* pool = threads > 0 ? new BuilderThreadPool() : NULL;
//
// m_tiles.sort([](MapTiles a, MapTiles b)
// {
// return a.m_tiles->size() > b.m_tiles->size();
// });
//
// for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it)
// {
// uint32 mapID = it->m_mapId;
// if (!shouldSkipMap(mapID))
// {
// if (threads > 0)
// pool->Enqueue(new MapBuildRequest(mapID));
// else
// buildMap(mapID);
// }
// }
//
// for (int i = 0; i < threads; ++i)
// _threads.push_back(new BuilderThread(this, pool->Queue()));
//
// // Free memory
// for (std::vector<BuilderThread*>::iterator _th = _threads.begin(); _th != _threads.end(); ++_th)
// {
// (*_th)->wait();
// delete *_th;
// }
//
// delete pool;
m_tiles.sort([](MapTiles a, MapTiles b)
{
return a.m_tiles->size() > b.m_tiles->size();
});
for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it)
{
uint32 mapID = it->m_mapId;
if (!shouldSkipMap(mapID))
{
if (threads > 0)
_queue.Push(mapID);
else
buildMap(mapID);
}
}
while (!_queue.Empty())
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
_cancelationToken = true;
_queue.Cancel();
for (auto& thread : _workerThreads)
{
thread.join();
}
}
/**************************************************************************/
+9
View File
@@ -23,12 +23,15 @@
#include <set>
#include <map>
#include <list>
#include <atomic>
#include <thread>
#include "TerrainBuilder.h"
#include "IntermediateValues.h"
#include "Recast.h"
#include "DetourNavMesh.h"
#include "ProducerConsumerQueue.h"
using namespace VMAP;
@@ -96,6 +99,8 @@ namespace MMAP
// builds list of maps, then builds all of mmap tiles (based on the skip settings)
void buildAllMaps(int threads);
void MapBuilder::WorkerThread();
private:
// detect maps and tiles
void discoverTiles();
@@ -138,6 +143,10 @@ namespace MMAP
// build performance - not really used for now
rcContext* m_rcContext;
std::vector<std::thread> _workerThreads;
ProducerConsumerQueue<uint32> _queue;
std::atomic<bool> _cancelationToken;
};
}
@@ -18,13 +18,11 @@
#include "TerrainBuilder.h"
#include "PathCommon.h"
#include "MapBuilder.h"
#include "VMapManager2.h"
#include "MapTree.h"
#include "ModelInstance.h"
#include <vector>
// ******************************************
// Map file format defines