Skip to content

Commit

Permalink
[popsift] adding state attribute _isInit
Browse files Browse the repository at this point in the history
and moving uninit in Pipe
fix #70
  • Loading branch information
simogasp committed Feb 4, 2020
1 parent df44615 commit 1f138d9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
52 changes: 39 additions & 13 deletions src/popsift/popsift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using namespace std;

PopSift::PopSift( const popsift::Config& config, popsift::Config::ProcessingMode mode, ImageMode imode )
: _image_mode( imode )
: _image_mode( imode ), _isInit(true)
{
if( imode == ByteImages )
{
Expand All @@ -38,7 +38,7 @@ PopSift::PopSift( const popsift::Config& config, popsift::Config::ProcessingMode
}

PopSift::PopSift( ImageMode imode )
: _image_mode( imode )
: _image_mode( imode ), _isInit(true)
{
if( imode == ByteImages )
{
Expand All @@ -58,6 +58,10 @@ PopSift::PopSift( ImageMode imode )

PopSift::~PopSift()
{
if(_isInit)
{
uninit();
}
}

bool PopSift::configure( const popsift::Config& config, bool force )
Expand Down Expand Up @@ -121,19 +125,14 @@ bool PopSift::private_init( int w, int h )

void PopSift::uninit( )
{
_pipe._queue_stage1.push( 0 );
_pipe._thread_stage2->join();
_pipe._thread_stage1->join();
delete _pipe._thread_stage2;
delete _pipe._thread_stage1;

while( !_pipe._unused.empty() ) {
popsift::ImageBase* img = _pipe._unused.pull();
delete img;
if(!_isInit)
{
std::cout << "[warning] Attempt to release resources from an uninitialized instance" << std::endl;
return;
}
_pipe.uninit();

delete _pipe._pyramid;
_pipe._pyramid = 0;
_isInit = false;
}

SiftJob* PopSift::enqueue( int w,
Expand Down Expand Up @@ -317,3 +316,30 @@ popsift::FeaturesDev* SiftJob::getDev()
return dynamic_cast<popsift::FeaturesDev*>( _f.get() );
}

void PopSift::Pipe::uninit()
{
_queue_stage1.push( nullptr );
if(_thread_stage2 != nullptr)
{
_thread_stage2->join();
delete _thread_stage2;
}
if(_thread_stage1 != nullptr)
{
_thread_stage1->join();
delete _thread_stage1;
}

while( !_unused.empty() )
{
popsift::ImageBase* img = _unused.pull();
delete img;
}

if(_pyramid != nullptr)
{
delete _pyramid;
_pyramid = nullptr;
}

}
20 changes: 16 additions & 4 deletions src/popsift/popsift.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class PopSift
popsift::ImageBase* _current;

popsift::Pyramid* _pyramid;

/**
* @brief Release the allocated resources, if any.
*/
void uninit();
};

public:
Expand All @@ -95,8 +100,8 @@ class PopSift
/* We support more than 1 streams, but we support only one sigma and one
* level parameters.
*/
PopSift( ImageMode imode = ByteImages );
PopSift( const popsift::Config& config,
explicit PopSift( ImageMode imode = ByteImages );
explicit PopSift( const popsift::Config& config,
popsift::Config::ProcessingMode mode = popsift::Config::ExtractingMode,
ImageMode imode = ByteImages );
~PopSift();
Expand All @@ -118,10 +123,14 @@ class PopSift
int h,
const float* imageData );

/** deprecated */
/**
* @deprecated
* */
inline void uninit( int /*pipe*/ ) { uninit(); }

/** deprecated */
/**
* @deprecated
**/
inline bool init( int /*pipe*/, int w, int h ) {
_last_init_w = w;
_last_init_h = h;
Expand Down Expand Up @@ -164,5 +173,8 @@ class PopSift
int _last_init_w; /* to support depreacted interface */
int _last_init_h; /* to support depreacted interface */
ImageMode _image_mode;

/// whether the object is initialized
bool _isInit{false};
};

0 comments on commit 1f138d9

Please sign in to comment.