Commit 4c22b514 authored by Sylvain Thery's avatar Sylvain Thery

optimized Dart/CellMarker destructor

parent 1cade09e
...@@ -47,13 +47,11 @@ protected: ...@@ -47,13 +47,11 @@ protected:
AttributeMultiVector<Mark>* m_markVector ; AttributeMultiVector<Mark>* m_markVector ;
unsigned int m_thread ; unsigned int m_thread ;
unsigned int m_cell ; unsigned int m_cell ;
bool releaseOnDestruct ;
public: public:
CellMarkerGen(unsigned int cell, unsigned int thread = 0) : CellMarkerGen(unsigned int cell, unsigned int thread = 0) :
m_thread(thread), m_thread(thread),
m_cell(cell), m_cell(cell)
releaseOnDestruct(true)
{} {}
virtual ~CellMarkerGen() virtual ~CellMarkerGen()
...@@ -69,10 +67,6 @@ protected: ...@@ -69,10 +67,6 @@ protected:
CellMarkerGen(const CellMarkerGen& /*cm*/) CellMarkerGen(const CellMarkerGen& /*cm*/)
{} {}
/**
* set if the mark has to be release on destruction or not
*/
void setReleaseOnDestruct(bool b) { releaseOnDestruct = b ; }
// virtual void mark(Dart d) = 0 ; // virtual void mark(Dart d) = 0 ;
// virtual void unmark(Dart d) = 0 ; // virtual void unmark(Dart d) = 0 ;
...@@ -108,7 +102,6 @@ public: ...@@ -108,7 +102,6 @@ public:
m_map.template addEmbedding<CELL>() ; m_map.template addEmbedding<CELL>() ;
m_mark = m_map.template getMarkerSet<CELL>(m_thread).getNewMark() ; m_mark = m_map.template getMarkerSet<CELL>(m_thread).getNewMark() ;
m_markVector = m_map.template getMarkVector<CELL>(m_thread) ; m_markVector = m_map.template getMarkVector<CELL>(m_thread) ;
m_map.cellMarkers[m_thread].push_back(this) ;
} }
CellMarkerBase(const MAP& map, unsigned int thread = 0) : CellMarkerBase(const MAP& map, unsigned int thread = 0) :
...@@ -119,26 +112,12 @@ public: ...@@ -119,26 +112,12 @@ public:
m_map.template addEmbedding<CELL>() ; m_map.template addEmbedding<CELL>() ;
m_mark = m_map.template getMarkerSet<CELL>(m_thread).getNewMark() ; m_mark = m_map.template getMarkerSet<CELL>(m_thread).getNewMark() ;
m_markVector = m_map.template getMarkVector<CELL>(m_thread) ; m_markVector = m_map.template getMarkVector<CELL>(m_thread) ;
m_map.cellMarkers[m_thread].push_back(this) ;
} }
virtual ~CellMarkerBase() virtual ~CellMarkerBase()
{ {
if(releaseOnDestruct) if (GenericMap::alive(&m_map))
{
m_map.template getMarkerSet<CELL>(m_thread).releaseMark(m_mark) ; m_map.template getMarkerSet<CELL>(m_thread).releaseMark(m_mark) ;
std::vector<CellMarkerGen*>& cmg = m_map.cellMarkers[m_thread];
for(std::vector<CellMarkerGen*>::iterator it = cmg.begin(); it != cmg.end(); ++it)
{
if(*it == this)
{
*it = cmg.back();
cmg.pop_back();
return;
}
}
}
} }
protected: protected:
......
...@@ -46,15 +46,13 @@ protected: ...@@ -46,15 +46,13 @@ protected:
Mark m_mark ; Mark m_mark ;
AttributeMultiVector<Mark>* m_markVector ; AttributeMultiVector<Mark>* m_markVector ;
unsigned int m_thread ; unsigned int m_thread ;
bool releaseOnDestruct ;
public: public:
/** /**
* constructor * constructor
*/ */
DartMarkerGen(unsigned int thread = 0) : DartMarkerGen(unsigned int thread = 0) :
m_thread(thread), m_thread(thread)
releaseOnDestruct(true)
{} {}
virtual ~DartMarkerGen() virtual ~DartMarkerGen()
...@@ -69,10 +67,6 @@ protected: ...@@ -69,10 +67,6 @@ protected:
DartMarkerGen(const DartMarkerGen& /*dm*/) DartMarkerGen(const DartMarkerGen& /*dm*/)
{} {}
/**
* set if the mark has to be release on destruction or not
*/
inline void setReleaseOnDestruct(bool b) { releaseOnDestruct = b ; }
} ; } ;
template <typename MAP> template <typename MAP>
...@@ -92,7 +86,6 @@ public: ...@@ -92,7 +86,6 @@ public:
{ {
m_mark = m_map.template getMarkerSet<DART>(m_thread).getNewMark() ; m_mark = m_map.template getMarkerSet<DART>(m_thread).getNewMark() ;
m_markVector = m_map.template getMarkVector<DART>(m_thread) ; m_markVector = m_map.template getMarkVector<DART>(m_thread) ;
m_map.dartMarkers[m_thread].push_back(this) ;
} }
DartMarkerTmpl(const MAP& map, unsigned int thread = 0) : DartMarkerTmpl(const MAP& map, unsigned int thread = 0) :
...@@ -101,25 +94,13 @@ public: ...@@ -101,25 +94,13 @@ public:
{ {
m_mark = m_map.template getMarkerSet<DART>(m_thread).getNewMark() ; m_mark = m_map.template getMarkerSet<DART>(m_thread).getNewMark() ;
m_markVector = m_map.template getMarkVector<DART>(m_thread) ; m_markVector = m_map.template getMarkVector<DART>(m_thread) ;
m_map.dartMarkers[m_thread].push_back(this) ;
} }
virtual ~DartMarkerTmpl() virtual ~DartMarkerTmpl()
{ {
if (releaseOnDestruct) if (GenericMap::alive(&m_map))
{
m_map.template getMarkerSet<DART>(m_thread).releaseMark(m_mark) ; m_map.template getMarkerSet<DART>(m_thread).releaseMark(m_mark) ;
std::vector<DartMarkerGen*>& dmg = m_map.dartMarkers[m_thread] ;
for (std::vector<DartMarkerGen*>::iterator it = dmg.begin(); it != dmg.end(); ++it)
{
if (*it == this)
{
*it = dmg.back() ;
dmg.pop_back() ;
return ;
}
}
}
} }
protected: protected:
......
...@@ -138,6 +138,9 @@ protected: ...@@ -138,6 +138,9 @@ protected:
std::vector<DartMarkerGen*> dartMarkers[NB_THREAD] ; std::vector<DartMarkerGen*> dartMarkers[NB_THREAD] ;
std::vector<CellMarkerGen*> cellMarkers[NB_THREAD] ; std::vector<CellMarkerGen*> cellMarkers[NB_THREAD] ;
// table of instancied maps for Dart/CellMarker release
static std::vector<GenericMap*> s_instances;
public: public:
static const unsigned int UNKNOWN_ATTRIB = AttributeContainer::UNKNOWN ; static const unsigned int UNKNOWN_ATTRIB = AttributeContainer::UNKNOWN ;
...@@ -145,6 +148,14 @@ public: ...@@ -145,6 +148,14 @@ public:
virtual ~GenericMap() ; virtual ~GenericMap() ;
static inline bool alive(GenericMap* map)
{
for (auto it=s_instances.begin(); it != s_instances.end(); ++it)
if (*it == map)
return true;
return false;
}
protected: protected:
void init(); void init();
......
...@@ -42,6 +42,9 @@ int NumberOfThreads = getSystemNumberOfCores(); ...@@ -42,6 +42,9 @@ int NumberOfThreads = getSystemNumberOfCores();
std::map<std::string, RegisteredBaseAttribute*>* GenericMap::m_attributes_registry_map = NULL; std::map<std::string, RegisteredBaseAttribute*>* GenericMap::m_attributes_registry_map = NULL;
int GenericMap::m_nbInstances = 0; int GenericMap::m_nbInstances = 0;
// table of instancied maps for Dart/CellMarker release
std::vector<GenericMap*> GenericMap::s_instances;
GenericMap::GenericMap() : m_nbThreadMarkers(1) GenericMap::GenericMap() : m_nbThreadMarkers(1)
{ {
if(m_attributes_registry_map == NULL) if(m_attributes_registry_map == NULL)
...@@ -81,6 +84,7 @@ GenericMap::GenericMap() : m_nbThreadMarkers(1) ...@@ -81,6 +84,7 @@ GenericMap::GenericMap() : m_nbThreadMarkers(1)
} }
m_nbInstances++; m_nbInstances++;
s_instances.push_back(this);
for(unsigned int i = 0; i < NB_ORBITS; ++i) for(unsigned int i = 0; i < NB_ORBITS; ++i)
{ {
...@@ -143,6 +147,9 @@ GenericMap::~GenericMap() ...@@ -143,6 +147,9 @@ GenericMap::~GenericMap()
delete m_attributes_registry_map; delete m_attributes_registry_map;
m_attributes_registry_map = NULL; m_attributes_registry_map = NULL;
} }
// remove instance for table
std::remove (s_instances.begin(), s_instances.end(), this);
} }
void GenericMap::init() void GenericMap::init()
......
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