Commit 5b821f0b authored by Sylvain Thery's avatar Sylvain Thery
Browse files

Protect attribute register/unregister with mutex

parent 3b81dd69
...@@ -176,7 +176,6 @@ public: ...@@ -176,7 +176,6 @@ public:
{ {
m_positions2[i] = 1.1f * m_positions[i]; m_positions2[i] = 1.1f * m_positions[i];
} }
// no need to duplicate here functor can be shared (no data), call foreach with true parameter
}; };
...@@ -283,7 +282,7 @@ void MyQT::threadStorage() ...@@ -283,7 +282,7 @@ void MyQT::threadStorage()
} }
CGoGNout << "using "<< nbthreads << " threads"<< CGoGNendl; CGoGNout << "using "<< nbthreads << " threads"<< CGoGNendl;
Algo::Parallel::foreach_cell<PFP::MAP,EDGE>(myMap, functs, nbthreads); Algo::Parallel::foreach_cell<PFP::MAP,EDGE>(myMap, functs);
//compute average length from each thread result and delete functors //compute average length from each thread result and delete functors
double average = 0; double average = 0;
......
...@@ -28,6 +28,7 @@ namespace CGoGN ...@@ -28,6 +28,7 @@ namespace CGoGN
template <typename T, unsigned int ORBIT> template <typename T, unsigned int ORBIT>
inline void AttributeHandler<T, ORBIT>::registerInMap() inline void AttributeHandler<T, ORBIT>::registerInMap()
{ {
boost::mutex::scoped_lock lockAH(m_map->attributeHandlersMutex);
m_map->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(m_attrib, this)) ; m_map->attributeHandlers.insert(std::pair<AttributeMultiVectorGen*, AttributeHandlerGen*>(m_attrib, this)) ;
} }
...@@ -35,6 +36,8 @@ template <typename T, unsigned int ORBIT> ...@@ -35,6 +36,8 @@ template <typename T, unsigned int ORBIT>
inline void AttributeHandler<T, ORBIT>::unregisterFromMap() inline void AttributeHandler<T, ORBIT>::unregisterFromMap()
{ {
typedef std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator IT ; typedef std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator IT ;
boost::mutex::scoped_lock lockAH(m_map->attributeHandlersMutex);
std::pair<IT, IT> bounds = m_map->attributeHandlers.equal_range(m_attrib) ; std::pair<IT, IT> bounds = m_map->attributeHandlers.equal_range(m_attrib) ;
for(IT i = bounds.first; i != bounds.second; ++i) for(IT i = bounds.first; i != bounds.second; ++i)
{ {
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include <map> #include <map>
#include <boost/thread/mutex.hpp>
#include "Container/attributeContainer.h" #include "Container/attributeContainer.h"
...@@ -113,6 +115,8 @@ protected: ...@@ -113,6 +115,8 @@ protected:
* Store links to created AttributeHandlers, DartMarkers and CellMarkers * Store links to created AttributeHandlers, DartMarkers and CellMarkers
*/ */
std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ; // TODO think of MT (AttributeHandler creation & release are not thread safe! std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ; // TODO think of MT (AttributeHandler creation & release are not thread safe!
boost::mutex attributeHandlersMutex;
std::vector<DartMarkerGen*> dartMarkers[NB_THREAD] ; std::vector<DartMarkerGen*> dartMarkers[NB_THREAD] ;
std::vector<CellMarkerGen*> cellMarkers[NB_THREAD] ; std::vector<CellMarkerGen*> cellMarkers[NB_THREAD] ;
......
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