Commit 83c31a67 authored by Guillaume Pasero's avatar Guillaume Pasero

ENH: use a trick to override ProcessObject::GetAbortGenerateData in a thread safe way

parent 28639b65
......@@ -143,8 +143,8 @@ public:
* This filter does not produce an output */
void Update() override;
// the interface of the superclass getter function is not thread safe
bool GetAbortGenerateDataMutex() const;
/** This override doesn't return a const ref on the actual boolean */
const bool & GetAbortGenerateData() const override;
void SetAbortGenerateData(const bool val) override;
......
......@@ -32,6 +32,7 @@
#include "otbTileDimensionTiledStreamingManager.h"
#include "otbRAMDrivenTiledStreamingManager.h"
#include "otbRAMDrivenAdaptativeStreamingManager.h"
#include "otbUtils.h"
namespace otb
{
......@@ -238,7 +239,7 @@ StreamingImageVirtualWriter<TInputImage>
*/
InputImageRegionType streamRegion;
for (m_CurrentDivision = 0;
m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateDataMutex();
m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateData();
m_CurrentDivision++, m_DivisionProgress = 0, this->UpdateFilterProgress())
{
streamRegion = m_StreamingManager->GetSplit(m_CurrentDivision);
......@@ -254,7 +255,7 @@ StreamingImageVirtualWriter<TInputImage>
* If we ended due to aborting, push the progress up to 1.0 (since
* it probably didn't end there)
*/
if (!this->GetAbortGenerateDataMutex())
if (!this->GetAbortGenerateData())
{
this->UpdateProgress(1.0);
}
......@@ -293,14 +294,15 @@ StreamingImageVirtualWriter<TInputImage>
}
template <class TInputImage>
bool
const bool &
StreamingImageVirtualWriter<TInputImage>
::GetAbortGenerateDataMutex() const
::GetAbortGenerateData() const
{
m_Lock.Lock();
bool ret = Superclass::GetAbortGenerateData();
m_Lock.Unlock();
return ret;
if (ret) return otb::Utils::TrueConstant;
return otb::Utils::FalseConstant;
}
template <class TInputImage>
......
......@@ -200,8 +200,8 @@ public:
itkGetObjectMacro(ImageIO, otb::ImageIOBase);
itkGetConstObjectMacro(ImageIO, otb::ImageIOBase);
// the interface of the superclass getter function is not thread safe
bool GetAbortGenerateDataMutex() const;
/** This override doesn't return a const ref on the actual boolean */
const bool & GetAbortGenerateData() const override;
void SetAbortGenerateData(const bool val) override;
......
......@@ -48,6 +48,7 @@
#include "otb_boost_tokenizer_header.h"
#include "otbStringUtils.h"
#include "otbUtils.h"
namespace otb
{
......@@ -604,7 +605,7 @@ ImageFileWriter<TInputImage>
}
for (m_CurrentDivision = 0;
m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateDataMutex();
m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateData();
m_CurrentDivision++, m_DivisionProgress = 0, this->UpdateFilterProgress())
{
streamRegion = m_StreamingManager->GetSplit(m_CurrentDivision);
......@@ -633,7 +634,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->GetAbortGenerateDataMutex())
if (!this->GetAbortGenerateData())
{
this->UpdateProgress(1.0);
}
......@@ -836,14 +837,16 @@ return this->m_FilenameHelper->GetSimpleFileName();
}
template <class TInputImage>
bool
const bool &
ImageFileWriter<TInputImage>
::GetAbortGenerateDataMutex() const
::GetAbortGenerateData() const
{
m_Lock.Lock();
// protected read here
bool ret = Superclass::GetAbortGenerateData();
m_Lock.Unlock();
return ret;
if (ret) return otb::Utils::TrueConstant;
return otb::Utils::FalseConstant;
}
template <class TInputImage>
......
......@@ -253,8 +253,8 @@ public:
itkSetMacro(TiffTiledMode, bool);
itkGetMacro(TiffTiledMode, bool);
// the interface of the superclass getter function is not thread safe
bool GetAbortGenerateDataMutex() const;
/** This override doesn't return a const ref on the actual boolean */
const bool & GetAbortGenerateData() const override;
void SetAbortGenerateData(bool val) override;
......
......@@ -23,6 +23,7 @@
#include "otbSimpleParallelTiffWriter.h"
#include "otbStopwatch.h"
#include "otbUtils.h"
using std::vector;
......@@ -682,7 +683,7 @@ SimpleParallelTiffWriter<TInputImage>
double processDuration(0), writeDuration(0), numberOfProcessedRegions(0);
InputImageRegionType streamRegion;
for (m_CurrentDivision = 0;
m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateDataMutex();
m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateData();
m_CurrentDivision++, m_DivisionProgress = 0, this->UpdateFilterProgress())
{
streamRegion = m_StreamingManager->GetSplit(m_CurrentDivision);
......@@ -717,7 +718,7 @@ SimpleParallelTiffWriter<TInputImage>
}
// abort case
if (this->GetAbortGenerateDataMutex())
if (this->GetAbortGenerateData())
{
itk::ProcessAborted e(__FILE__, __LINE__);
e.SetLocation(ITK_LOCATION);
......@@ -768,7 +769,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->GetAbortGenerateDataMutex())
if (!this->GetAbortGenerateData())
{
this->UpdateProgress(1.0);
}
......@@ -835,14 +836,15 @@ SimpleParallelTiffWriter<TInputImage>
}
template <class TInputImage>
bool
const bool &
SimpleParallelTiffWriter<TInputImage>
::GetAbortGenerateDataMutex() const
::GetAbortGenerateData() const
{
m_Lock.Lock();
bool ret = Superclass::GetAbortGenerateData();
m_Lock.Unlock();
return ret;
if (ret) return otb::Utils::TrueConstant;
return otb::Utils::FalseConstant;
}
template <class TInputImage>
......
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