diff options
author | Sebastian Valle <s.v.h21@hotmail.com> | 2013-10-06 21:22:38 -0500 |
---|---|---|
committer | Sebastian Valle <s.v.h21@hotmail.com> | 2013-10-06 21:22:38 -0500 |
commit | b1ed66b52dc63240d73e55cf43bc3e4c60e183ef (patch) | |
tree | 3e2ce7556dc3e72b6513a680dbf1f01f1ee00d17 | |
parent | f6d8b235e2fd52f2bc7f25fe56783c565cf7144a (diff) |
Tools/MeshExtractor: Added some locks because concurrency.
Race conditions were detected with a race condition detection tool.
-rw-r--r-- | src/tools/mesh_extractor/ContinentBuilder.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/tools/mesh_extractor/ContinentBuilder.cpp b/src/tools/mesh_extractor/ContinentBuilder.cpp index 4cb0a676e79..5130f467403 100644 --- a/src/tools/mesh_extractor/ContinentBuilder.cpp +++ b/src/tools/mesh_extractor/ContinentBuilder.cpp @@ -8,9 +8,14 @@ #include "Recast.h" #include "DetourCommon.h" +#include <ace/Atomic_Op.h> +#include <ace/Guard_T.h> +#include <ace/Synch.h> + class BuilderThread : public ACE_Task_Base { private: + ACE_Thread_Mutex lock; int X, Y, MapId; std::string Continent; dtNavMeshParams Params; @@ -19,7 +24,8 @@ public: BuilderThread(ContinentBuilder* _cBuilder, dtNavMeshParams& params) : Params(params), cBuilder(_cBuilder), Free(true) {} void SetData(int x, int y, int map, const std::string& cont) - { + { + ACE_GUARD(ACE_Thread_Mutex, g, lock); X = x; Y = y; MapId = map; @@ -29,6 +35,7 @@ public: int svc() { + ACE_GUARD_RETURN(ACE_Thread_Mutex, g, lock, 0); printf("[%02i,%02i] Building tile\n", X, Y); TileBuilder builder(cBuilder, Continent, X, Y, MapId); char buff[100]; @@ -62,7 +69,7 @@ public: return 0; } - bool Free; + ACE_Atomic_Op<ACE_Thread_Mutex, bool> Free; }; void ContinentBuilder::getTileBounds(uint32 tileX, uint32 tileY, float* verts, int vertCount, float* bmin, float* bmax) @@ -171,7 +178,7 @@ void ContinentBuilder::Build() { for (std::vector<BuilderThread*>::iterator _th = Threads.begin(); _th != Threads.end(); ++_th) { - if ((*_th)->Free) + if ((*_th)->Free.value()) { (*_th)->SetData(itr->X, itr->Y, MapId, Continent); (*_th)->activate(); |