Commit f7ca9402 authored by Julien Michel's avatar Julien Michel

ENH: Adding mutex to keep thread safety

parent f023ffd7
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "itkObjectFactory.h" #include "itkObjectFactory.h"
#include "itkIndex.h" #include "itkIndex.h"
#include "itkSize.h" #include "itkSize.h"
#include "itkFastMutexLock.h"
namespace otb namespace otb
{ {
...@@ -171,6 +172,9 @@ private: ...@@ -171,6 +172,9 @@ private:
// Is the splitter up-to-date ? // Is the splitter up-to-date ?
bool m_IsUpToDate; bool m_IsUpToDate;
// Lock to ensure thread-safety
itk::SimpleFastMutexLock m_Lock;
}; };
} // end namespace otb } // end namespace otb
......
...@@ -38,11 +38,13 @@ ImageRegionAdaptativeSplitter<VImageDimension> ...@@ -38,11 +38,13 @@ ImageRegionAdaptativeSplitter<VImageDimension>
this->SetRequestedNumberOfSplits(requestedNumber); this->SetRequestedNumberOfSplits(requestedNumber);
// Check if we need to compute split map agagin // Check if we need to compute split map agagin
m_Lock.Lock();
if(!m_IsUpToDate) if(!m_IsUpToDate)
{ {
// Do so if we need to // Do so if we need to
this->EstimateSplitMap(); this->EstimateSplitMap();
} }
m_Lock.Unlock();
// Return the size of the split map // Return the size of the split map
return m_StreamVector.size(); return m_StreamVector.size();
...@@ -57,11 +59,13 @@ ImageRegionAdaptativeSplitter<VImageDimension> ...@@ -57,11 +59,13 @@ ImageRegionAdaptativeSplitter<VImageDimension>
this->SetImageRegion(region); this->SetImageRegion(region);
// Check if we need to compute split map agagin // Check if we need to compute split map agagin
m_Lock.Lock();
if(!m_IsUpToDate) if(!m_IsUpToDate)
{ {
// Do so if we need to // Do so if we need to
this->EstimateSplitMap(); this->EstimateSplitMap();
} }
m_Lock.Unlock();
// Return the requested split // Return the requested split
return m_StreamVector.at(i); return m_StreamVector.at(i);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment