Compare commits
3 Commits
4fdacb9294
...
618e2b7a2a
Author | SHA1 | Date | |
---|---|---|---|
618e2b7a2a | |||
d3fa101aeb | |||
0f2e11e735 |
@ -10,6 +10,22 @@
|
||||
|
||||
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() {
|
||||
if (m_refCount != 0) {
|
||||
EMEMORY_ERROR("delete a RefCounted element that is keep by somewhere !! " << m_refCount);
|
||||
@ -30,11 +46,23 @@ void ememory::RefCounter::refRelease() {
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
int ememory::RefCounter::getRefCount() const {
|
||||
return m_refCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint64_t ememory::RefCounter::getRawPointer() const {
|
||||
#ifdef DEBUG
|
||||
return m_uid;
|
||||
#endif
|
||||
return uint64_t(this);
|
||||
}
|
||||
|
@ -14,11 +14,19 @@ namespace ememory {
|
||||
* @brief Use the element as a refcounted element
|
||||
*/
|
||||
class RefCounter {
|
||||
protected:
|
||||
#ifndef ETK_MEMORY_CHECKER
|
||||
protected:
|
||||
#else
|
||||
public:
|
||||
#endif
|
||||
RefCounter();
|
||||
// Virtualize destructor in private to prevent user ot remove it without permition
|
||||
virtual ~RefCounter();
|
||||
private:
|
||||
int32_t m_refCount = 1;
|
||||
#ifdef DEBUG
|
||||
int32_t m_uid;
|
||||
#endif
|
||||
public:
|
||||
/**
|
||||
* @brief Keep a copy of this reference-counted element.
|
||||
@ -42,7 +50,15 @@ namespace ememory {
|
||||
* @return Request const SharedPtr
|
||||
*/
|
||||
//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>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.tools as tools
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.tools as tools
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user