Compare commits

...

3 Commits

4 changed files with 49 additions and 5 deletions

View File

@ -10,6 +10,22 @@
ETK_DECLARE_TYPE(ememory::RefCounter); ETK_DECLARE_TYPE(ememory::RefCounter);
#ifdef DEBUG
static int32_t& getLocalDebugCounter() {
static int32_t g_uid = 0;
return g_uid;
}
void ememory::resetDebugRefCounter() {
getLocalDebugCounter() = 0;
}
#endif
ememory::RefCounter::RefCounter() {
#ifdef DEBUG
m_uid = getLocalDebugCounter()++;
#endif
}
ememory::RefCounter::~RefCounter() { ememory::RefCounter::~RefCounter() {
if (m_refCount != 0) { if (m_refCount != 0) {
EMEMORY_ERROR("delete a RefCounted element that is keep by somewhere !! " << m_refCount); EMEMORY_ERROR("delete a RefCounted element that is keep by somewhere !! " << m_refCount);
@ -30,11 +46,23 @@ void ememory::RefCounter::refRelease() {
return; return;
} }
if (refCount < 0) { if (refCount < 0) {
EMEMORY_ERROR("request release a refcounted One more time than needed !! " << m_refCount); #ifdef DEBUG
EMEMORY_ERROR("request release a refcounted One more time than needed !! " << m_refCount << " uid=" << m_uid);
#else
EMEMORY_ERROR("request release a refcounted One more time than needed !! " << m_refCount);
#endif
m_refCount = 0; m_refCount = 0;
} }
} }
int ememory::RefCounter::getRefCount() const { int ememory::RefCounter::getRefCount() const {
return m_refCount; return m_refCount;
} }
uint64_t ememory::RefCounter::getRawPointer() const {
#ifdef DEBUG
return m_uid;
#endif
return uint64_t(this);
}

View File

@ -14,11 +14,19 @@ namespace ememory {
* @brief Use the element as a refcounted element * @brief Use the element as a refcounted element
*/ */
class RefCounter { class RefCounter {
protected: #ifndef ETK_MEMORY_CHECKER
protected:
#else
public:
#endif
RefCounter();
// Virtualize destructor in private to prevent user ot remove it without permition // Virtualize destructor in private to prevent user ot remove it without permition
virtual ~RefCounter(); virtual ~RefCounter();
private: private:
int32_t m_refCount = 1; int32_t m_refCount = 1;
#ifdef DEBUG
int32_t m_uid;
#endif
public: public:
/** /**
* @brief Keep a copy of this reference-counted element. * @brief Keep a copy of this reference-counted element.
@ -42,7 +50,15 @@ namespace ememory {
* @return Request const SharedPtr * @return Request const SharedPtr
*/ */
//const ememory::RefPtr<EMEMORY_TYPE> refFromThis() const; //const ememory::RefPtr<EMEMORY_TYPE> refFromThis() const;
protected:
/**
* @brief get the RAW pointer value of this element (for debug only)
*/
uint64_t getRawPointer() const;
}; };
#ifdef DEBUG
void resetDebugRefCounter();
#endif
} }
#include <ememory/details/EnableSharedFromThis.hxx> #include <ememory/details/EnableSharedFromThis.hxx>

View File

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import lutin.debug as debug import realog.debug as debug
import lutin.tools as tools import lutin.tools as tools

View File

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import lutin.debug as debug import realog.debug as debug
import lutin.tools as tools import lutin.tools as tools