diff options
| -rw-r--r-- | src/server/shared/Database/DatabaseWorkerPool.h | 5 | ||||
| -rw-r--r-- | src/tools/mmaps_generator/MapBuilder.cpp | 31 | ||||
| -rw-r--r-- | src/tools/mmaps_generator/MapBuilder.h | 55 |
3 files changed, 56 insertions, 35 deletions
diff --git a/src/server/shared/Database/DatabaseWorkerPool.h b/src/server/shared/Database/DatabaseWorkerPool.h index 3df9436a4c4..edbc41be8f7 100644 --- a/src/server/shared/Database/DatabaseWorkerPool.h +++ b/src/server/shared/Database/DatabaseWorkerPool.h @@ -56,9 +56,7 @@ class DatabaseWorkerPool _connections.resize(IDX_SIZE); WPFatal (mysql_thread_safe(), "Used MySQL library isn't thread-safe."); - WPFatal (mysql_get_server_version() >= MIN_MYSQL_SERVER_VERSION && - mysql_get_client_version() >= MIN_MYSQL_CLIENT_VERSION, - "TrinityCore does not support MySQL versions below 5.1"); + WPFatal (mysql_get_client_version() >= MIN_MYSQL_CLIENT_VERSION, "TrinityCore does not support MySQL versions below 5.1"); } ~DatabaseWorkerPool() @@ -79,6 +77,7 @@ class DatabaseWorkerPool { T* t = new T(_queue, _connectionInfo); res &= t->Open(); + WPFatal (mysql_get_server_version(t->GetHandle()) >= MIN_MYSQL_SERVER_VERSION, "TrinityCore does not support MySQL versions below 5.1"); _connections[IDX_ASYNC][i] = t; ++_connectionCount[IDX_ASYNC]; } diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp index a62011ddfff..4707feb5857 100644 --- a/src/tools/mmaps_generator/MapBuilder.cpp +++ b/src/tools/mmaps_generator/MapBuilder.cpp @@ -166,45 +166,32 @@ namespace MMAP void MapBuilder::buildAllMaps(int threads) { std::vector<BuilderThread*> _threads; - - for (int i = 0; i < threads; ++i) - _threads.push_back(new BuilderThread(this)); + + BuilderThreadPool* pool = new BuilderThreadPool(); for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it) { uint32 mapID = it->first; if (!shouldSkipMap(mapID)) { - if (threads > 1) - { - bool next = false; - while (!next) - { - for (std::vector<BuilderThread*>::iterator _th = _threads.begin(); _th != _threads.end(); ++_th) - { - if ((*_th)->Free) - { - (*_th)->SetMapId(mapID); - (*_th)->activate(); - next = true; - break; - } - } - // Wait for 20 seconds - ACE_OS::sleep(ACE_Time_Value (0, 20000)); - } - } + if (threads > 0) + pool->Enqueue(new BuildAMapPlz(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; } /**************************************************************************/ diff --git a/src/tools/mmaps_generator/MapBuilder.h b/src/tools/mmaps_generator/MapBuilder.h index ea9636b3cc3..ea805fd9235 100644 --- a/src/tools/mmaps_generator/MapBuilder.h +++ b/src/tools/mmaps_generator/MapBuilder.h @@ -30,6 +30,8 @@ #include "DetourNavMesh.h" #include <ace/Task.h> +#include <ace/Activation_Queue.h> +#include <ace/Method_Request.h> using namespace VMAP; @@ -123,27 +125,60 @@ namespace MMAP // build performance - not really used for now rcContext* m_rcContext; }; + + class BuildAMapPlz : public ACE_Method_Request + { + public: + BuildAMapPlz(uint32 mapId) : _mapId(mapId) {} + + virtual int call() + { + /// @ Actually a creative way of unabstracting the class and returning a member variable + return (int)_mapId; + } + + private: + uint32 _mapId; + }; class BuilderThread : public ACE_Task<ACE_MT_SYNCH> { private: MapBuilder* _builder; - uint32 _mapId; - public: - BuilderThread(MapBuilder* builder) : _builder(builder), Free(true) {} - - void SetMapId(uint32 mapId) { _mapId = mapId; } + ACE_Activation_Queue* _queue; + public: + BuilderThread(MapBuilder* builder, ACE_Activation_Queue* queue) : _builder(builder), _queue(queue) { activate(); } + int svc() { - Free = false; - if (_builder) - _builder->buildMap(_mapId); - Free = true; + BuildAMapPlz* request = NULL; + while (request = (BuildAMapPlz*)_queue->dequeue()) + { + _builder->buildMap(request->call()); + delete request; + request = NULL; + } return 0; } - bool Free; + }; + + class BuilderThreadPool + { + public: + BuilderThreadPool() : _queue(new ACE_Activation_Queue()) {} + ~BuilderThreadPool() { _queue->queue()->close(); delete _queue; } + + void Enqueue(BuildAMapPlz* request) + { + _queue->enqueue(request); + } + + ACE_Activation_Queue* Queue() { return _queue; } + + private: + ACE_Activation_Queue* _queue; }; } |
