Skip to content
Snippets Groups Projects
Commit a048449d authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

ENH: protect AbortGenerateData with mutex for ImageFileReader

parent 496253f0
No related branches found
No related tags found
Loading
......@@ -25,6 +25,7 @@
#include "itkProcessObject.h"
#include "otbStreamingManager.h"
#include "otbExtendedFilenameToWriterOptions.h"
#include "itkFastMutexLock.h"
namespace otb
{
......@@ -199,6 +200,11 @@ public:
itkGetObjectMacro(ImageIO, otb::ImageIOBase);
itkGetConstObjectMacro(ImageIO, otb::ImageIOBase);
// the interface of the superclass getter function is not thread safe
bool GetAbortGenerateDataMutex() const;
void SetAbortGenerateData(bool val) override;
protected:
ImageFileWriter();
~ImageFileWriter() ITK_OVERRIDE;
......@@ -270,6 +276,9 @@ private:
* This variable can be the number of components in m_ImageIO or the
* number of components in the m_BandList (if used) */
unsigned int m_IOComponents;
/** Lock to ensure thread-safety (added for the AbortGenerateData flag) */
itk::SimpleFastMutexLock m_Lock;
};
} // end namespace otb
......
......@@ -616,7 +616,7 @@ ImageFileWriter<TInputImage>
}
for (m_CurrentDivision = 0;
m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateData();
m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateDataMutex();
m_CurrentDivision++, m_DivisionProgress = 0, this->UpdateFilterProgress())
{
streamRegion = m_StreamingManager->GetSplit(m_CurrentDivision);
......@@ -645,7 +645,7 @@ ImageFileWriter<TInputImage>
* If we ended due to aborting, push the progress up to 1.0 (since
* it probably didn't end there)
*/
if (!this->GetAbortGenerateData())
if (!this->GetAbortGenerateDataMutex())
{
this->UpdateProgress(1.0);
}
......@@ -843,6 +843,27 @@ ImageFileWriter<TInputImage>
return this->m_FilenameHelper->GetSimpleFileName();
}
template <class TInputImage>
bool
ImageFileWriter<TInputImage>
::GetAbortGenerateDataMutex() const
{
m_Lock.Lock();
bool ret = Superclass::GetAbortGenerateData();
m_Lock.Unlock();
return ret;
}
template <class TInputImage>
void
ImageFileWriter<TInputImage>
::SetAbortGenerateData(bool val)
{
m_Lock.Lock();
Superclass::SetAbortGenerateData(val);
m_Lock.Unlock();
}
} // end namespace otb
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment