mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Tools/mmap_generator: Fixed a deadlock at exit
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user