diff options
-rw-r--r-- | src/tools/mmaps_generator/MapBuilder.cpp | 8 | ||||
-rw-r--r-- | src/tools/mmaps_generator/MapBuilder.h | 20 | ||||
-rw-r--r-- | src/tools/mmaps_generator/PathGenerator.cpp | 2 |
3 files changed, 16 insertions, 14 deletions
diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp index 4707feb5857..4a016f267b4 100644 --- a/src/tools/mmaps_generator/MapBuilder.cpp +++ b/src/tools/mmaps_generator/MapBuilder.cpp @@ -166,8 +166,8 @@ namespace MMAP void MapBuilder::buildAllMaps(int threads) { std::vector<BuilderThread*> _threads; - - BuilderThreadPool* pool = new BuilderThreadPool(); + + BuilderThreadPool* pool = threads > 0 ? new BuilderThreadPool() : NULL; for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it) { @@ -175,13 +175,13 @@ namespace MMAP if (!shouldSkipMap(mapID)) { if (threads > 0) - pool->Enqueue(new BuildAMapPlz(mapID)); + pool->Enqueue(new MapBuildRequest(mapID)); else buildMap(mapID); } } - for (int i = 0; i < threads; ++i) + for (int i = 0; i < threads; ++i) _threads.push_back(new BuilderThread(this, pool->Queue())); // Free memory diff --git a/src/tools/mmaps_generator/MapBuilder.h b/src/tools/mmaps_generator/MapBuilder.h index ea805fd9235..3ffaea0ab66 100644 --- a/src/tools/mmaps_generator/MapBuilder.h +++ b/src/tools/mmaps_generator/MapBuilder.h @@ -125,11 +125,11 @@ namespace MMAP // build performance - not really used for now rcContext* m_rcContext; }; - - class BuildAMapPlz : public ACE_Method_Request + + class MapBuildRequest : public ACE_Method_Request { public: - BuildAMapPlz(uint32 mapId) : _mapId(mapId) {} + MapBuildRequest(uint32 mapId) : _mapId(mapId) {} virtual int call() { @@ -141,7 +141,7 @@ namespace MMAP uint32 _mapId; }; - class BuilderThread : public ACE_Task<ACE_MT_SYNCH> + class BuilderThread : public ACE_Task_Base { private: MapBuilder* _builder; @@ -149,19 +149,21 @@ namespace MMAP public: BuilderThread(MapBuilder* builder, ACE_Activation_Queue* queue) : _builder(builder), _queue(queue) { activate(); } - + int svc() { - BuildAMapPlz* request = NULL; - while (request = (BuildAMapPlz*)_queue->dequeue()) + /// @ Set a timeout for dequeue attempts (only used when the queue is empty) as it will never get populated after thread starts + ACE_Time_Value timeout(5); + ACE_Method_Request* request = NULL; + while ((request = _queue->dequeue(&timeout)) != NULL) { _builder->buildMap(request->call()); delete request; request = NULL; } + return 0; } - }; class BuilderThreadPool @@ -170,7 +172,7 @@ namespace MMAP BuilderThreadPool() : _queue(new ACE_Activation_Queue()) {} ~BuilderThreadPool() { _queue->queue()->close(); delete _queue; } - void Enqueue(BuildAMapPlz* request) + void Enqueue(MapBuildRequest* request) { _queue->enqueue(request); } diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp index 01059099f98..47d35b517d5 100644 --- a/src/tools/mmaps_generator/PathGenerator.cpp +++ b/src/tools/mmaps_generator/PathGenerator.cpp @@ -292,5 +292,5 @@ int main(int argc, char** argv) if (!silent) printf("Finished. MMAPS were built in %u ms!\n", GetMSTimeDiffToNow(start)); - return 1; + return 0; } |