Commit 750e80f1 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[FIX #244] Fixed another memory leak. This should fix #244 now.

parent eed37251
......@@ -197,8 +197,35 @@ void WROIManagerFibers::recalculate()
void WROIManagerFibers::setDirty()
{
WUpdateThread* t = new WUpdateThread( shared_from_this() );
t->run();
boost::unique_lock< boost::shared_mutex > lock;
{
boost::shared_ptr< WUpdateThread > t = boost::shared_ptr< WUpdateThread >( new WUpdateThread( shared_from_this() ) );
t->run();
lock = boost::unique_lock< boost::shared_mutex >( m_updateListLock );
m_updateThreads.push_back( t );
lock.unlock();
}
{
lock = boost::unique_lock< boost::shared_mutex >( m_updateListLock );
std::list< boost::shared_ptr< WUpdateThread > >::iterator itr;
// remove finished threads
for( itr = m_updateThreads.begin(); itr != m_updateThreads.end(); )
{
if( ( *itr )->isFinished() )
{
itr = m_updateThreads.erase( itr );
}
else
{
++itr;
}
}
lock.unlock();
}
}
boost::shared_ptr< const WDataSetFibers > WROIManagerFibers::getDataSet()
......
......@@ -34,6 +34,7 @@
#include "WMFiberDisplay.h"
#include "WRMBranch.h"
#include "WUpdateThread.h"
/**
* Class to store and manage different ROI's for fiber selection
......@@ -152,10 +153,14 @@ private:
std::list< boost::shared_ptr< WRMBranch > > m_branches; //!< list of branches in the logical tree structure
std::list< boost::shared_ptr< WUpdateThread > > m_updateThreads; //!< list ofcurrent update threads.
boost::shared_mutex m_updateListLock; //!< Lock to prevent concurrent threads trying to update the list
/**
* Stores a pointer to the kdTree used for fiber selection
*/
boost::shared_ptr< WKdTree >m_kdTree;
boost::shared_ptr< WKdTree > m_kdTree;
/**
* Lock for associated notifiers set.
......
......@@ -26,9 +26,10 @@
#include "WUpdateThread.h"
WUpdateThread::WUpdateThread( boost::shared_ptr< WROIManagerFibers >roiManager ):
WUpdateThread::WUpdateThread( boost::shared_ptr< WROIManagerFibers > roiManager ):
WThreadedRunner(),
m_roiManager( roiManager )
m_roiManager( roiManager ),
m_myThreadFinished( false )
{
}
......@@ -39,4 +40,5 @@ WUpdateThread::~WUpdateThread()
void WUpdateThread::threadMain()
{
m_roiManager->recalculate();
m_myThreadFinished = true;
}
......@@ -44,16 +44,27 @@ public:
/**
* destructor
*/
~WUpdateThread();
virtual ~WUpdateThread();
/**
* entry for the run command
*/
virtual void threadMain();
/**
* Return the value of the finished flag.
*/
inline bool isFinished();
protected:
private:
boost::shared_ptr< WROIManagerFibers >m_roiManager; //!< stores pointer to the roi manager
boost::shared_ptr< WROIManagerFibers > m_roiManager; //!< stores pointer to the roi manager
bool m_myThreadFinished; //!< Has the thread finished?
};
bool WUpdateThread::isFinished()
{
return m_myThreadFinished;
}
#endif // WUPDATETHREAD_H
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