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

ENH: Abort supported in SimpleParallelTiffWriter

parent a83446dc
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@
#include "itkImageFileWriter.h"
#include "itkObjectFactoryBase.h"
#include "itkFastMutexLock.h"
#include "itkImageRegionMultidimensionalSplitter.h"
#include "otbImageIOFactory.h"
......@@ -252,6 +253,11 @@ public:
itkSetMacro(TiffTiledMode, bool);
itkGetMacro(TiffTiledMode, bool);
// the interface of the superclass getter function is not thread safe
bool GetAbortGenerateDataMutex() const;
void SetAbortGenerateData(bool val) override;
protected:
SimpleParallelTiffWriter();
virtual ~SimpleParallelTiffWriter();
......@@ -325,6 +331,9 @@ private:
bool m_Verbose;
bool m_VirtualMode;
bool m_TiffTiledMode;
/** Lock to ensure thread-safety (added for the AbortGenerateData flag) */
itk::SimpleFastMutexLock m_Lock;
};
......
......@@ -682,7 +682,7 @@ SimpleParallelTiffWriter<TInputImage>
double processDuration(0), writeDuration(0), numberOfProcessedRegions(0);
InputImageRegionType streamRegion;
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);
......@@ -716,6 +716,16 @@ SimpleParallelTiffWriter<TInputImage>
}
}
// abort case
if (this->GetAbortGenerateDataMutex())
{
itk::ProcessAborted e(__FILE__, __LINE__);
e.SetLocation(ITK_LOCATION);
e.SetDescription("Image writing has been aborted");
throw e;
otb::MPIConfig::Instance()->abort(EXIT_FAILURE);
}
// Clean up
close_raster(output_raster);
output_raster = NULL;
......@@ -758,7 +768,7 @@ SimpleParallelTiffWriter<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);
}
......@@ -824,5 +834,26 @@ SimpleParallelTiffWriter<TInputImage>
return this->m_FilenameHelper->GetSimpleFileName();
}
template <class TInputImage>
bool
SimpleParallelTiffWriter<TInputImage>
::GetAbortGenerateDataMutex() const
{
m_Lock.Lock();
bool ret = Superclass::GetAbortGenerateData();
m_Lock.Unlock();
return ret;
}
template <class TInputImage>
void
SimpleParallelTiffWriter<TInputImage>
::SetAbortGenerateData(bool val)
{
m_Lock.Lock();
Superclass::SetAbortGenerateData(val);
m_Lock.Unlock();
}
}
#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