|
|
@ -67,7 +67,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
|
|
|
|
|
|
|
|
|
|
struct _RefCountLeakCheck |
|
|
|
struct _RefCountLeakCheck |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::unordered_set<_hsRefCnt_Base *> m_refs; |
|
|
|
std::unordered_set<hsRefCnt *> m_refs; |
|
|
|
unsigned m_added, m_removed; |
|
|
|
unsigned m_added, m_removed; |
|
|
|
std::mutex m_mutex; |
|
|
|
std::mutex m_mutex; |
|
|
|
|
|
|
|
|
|
|
@ -81,7 +81,7 @@ struct _RefCountLeakCheck |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
_LeakDebug(plFormat(" {} objects leaked...\n", m_refs.size()).c_str()); |
|
|
|
_LeakDebug(plFormat(" {} objects leaked...\n", m_refs.size()).c_str()); |
|
|
|
for (_hsRefCnt_Base *ref : m_refs) { |
|
|
|
for (hsRefCnt *ref : m_refs) { |
|
|
|
_LeakDebug(plFormat(" 0x{_08x} {}: {} refs remain\n", |
|
|
|
_LeakDebug(plFormat(" 0x{_08x} {}: {} refs remain\n", |
|
|
|
(uintptr_t)ref, typeid(*ref).name(), ref->RefCnt()).c_str()); |
|
|
|
(uintptr_t)ref, typeid(*ref).name(), ref->RefCnt()).c_str()); |
|
|
|
} |
|
|
|
} |
|
|
@ -93,7 +93,7 @@ struct _RefCountLeakCheck |
|
|
|
return &s_instance; |
|
|
|
return &s_instance; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void add(_hsRefCnt_Base *ref) |
|
|
|
static void add(hsRefCnt *ref) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_RefCountLeakCheck *this_p = _instance(); |
|
|
|
_RefCountLeakCheck *this_p = _instance(); |
|
|
|
std::lock_guard<std::mutex> lock(this_p->m_mutex); |
|
|
|
std::lock_guard<std::mutex> lock(this_p->m_mutex); |
|
|
@ -101,7 +101,7 @@ struct _RefCountLeakCheck |
|
|
|
this_p->m_refs.insert(ref); |
|
|
|
this_p->m_refs.insert(ref); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void del(_hsRefCnt_Base *ref) |
|
|
|
static void del(hsRefCnt *ref) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_RefCountLeakCheck *this_p = _instance(); |
|
|
|
_RefCountLeakCheck *this_p = _instance(); |
|
|
|
std::lock_guard<std::mutex> lock(this_p->m_mutex); |
|
|
|
std::lock_guard<std::mutex> lock(this_p->m_mutex); |
|
|
@ -111,47 +111,26 @@ struct _RefCountLeakCheck |
|
|
|
}; |
|
|
|
}; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
_hsRefCnt_Base::_hsRefCnt_Base(int) |
|
|
|
hsRefCnt::hsRefCnt(int initRefs) |
|
|
|
|
|
|
|
: fRefCnt(initRefs) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#if (REFCOUNT_DEBUGGING == REFCOUNT_DBG_LEAKS) || (REFCOUNT_DEBUGGING == REFCOUNT_DBG_ALL) |
|
|
|
#if (REFCOUNT_DEBUGGING == REFCOUNT_DBG_LEAKS) || (REFCOUNT_DEBUGGING == REFCOUNT_DBG_ALL) |
|
|
|
_RefCountLeakCheck::add(this); |
|
|
|
_RefCountLeakCheck::add(this); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_hsRefCnt_Base::~_hsRefCnt_Base() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
#if (REFCOUNT_DEBUGGING == REFCOUNT_DBG_LEAKS) || (REFCOUNT_DEBUGGING == REFCOUNT_DBG_ALL) |
|
|
|
|
|
|
|
_RefCountLeakCheck::del(this); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hsRefCnt::~hsRefCnt() |
|
|
|
hsRefCnt::~hsRefCnt() |
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef HS_DEBUGGING |
|
|
|
#ifdef HS_DEBUGGING |
|
|
|
hsThrowIfFalse(fRefCnt == 1); |
|
|
|
hsThrowIfFalse(fRefCnt == 1); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void hsRefCnt::UnRef() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
#ifdef HS_DEBUGGING |
|
|
|
|
|
|
|
hsThrowIfFalse(fRefCnt >= 1); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fRefCnt == 1) // don't decrement if we call delete
|
|
|
|
#if (REFCOUNT_DEBUGGING == REFCOUNT_DBG_LEAKS) || (REFCOUNT_DEBUGGING == REFCOUNT_DBG_ALL) |
|
|
|
delete this; |
|
|
|
_RefCountLeakCheck::del(this); |
|
|
|
else |
|
|
|
|
|
|
|
--fRefCnt; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hsAtomicRefCnt::~hsAtomicRefCnt() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
#ifdef HS_DEBUGGING |
|
|
|
|
|
|
|
hsThrowIfFalse(fRefCnt == 1); |
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void hsAtomicRefCnt::UnRef(const char* tag) |
|
|
|
void hsRefCnt::UnRef(const char* tag) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef HS_DEBUGGING |
|
|
|
#ifdef HS_DEBUGGING |
|
|
|
hsThrowIfFalse(fRefCnt >= 1); |
|
|
|
hsThrowIfFalse(fRefCnt >= 1); |
|
|
@ -170,7 +149,7 @@ void hsAtomicRefCnt::UnRef(const char* tag) |
|
|
|
--fRefCnt; |
|
|
|
--fRefCnt; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void hsAtomicRefCnt::Ref(const char* tag) |
|
|
|
void hsRefCnt::Ref(const char* tag) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#if (REFCOUNT_DEBUGGING == REFCOUNT_DBG_REFS) || (REFCOUNT_DEBUGGING == REFCOUNT_DBG_ALL) |
|
|
|
#if (REFCOUNT_DEBUGGING == REFCOUNT_DBG_REFS) || (REFCOUNT_DEBUGGING == REFCOUNT_DBG_ALL) |
|
|
|
if (tag) |
|
|
|
if (tag) |
|
|
@ -182,7 +161,7 @@ void hsAtomicRefCnt::Ref(const char* tag) |
|
|
|
++fRefCnt; |
|
|
|
++fRefCnt; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void hsAtomicRefCnt::TransferRef(const char* oldTag, const char* newTag) |
|
|
|
void hsRefCnt::TransferRef(const char* oldTag, const char* newTag) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#if (REFCOUNT_DEBUGGING == REFCOUNT_DBG_REFS) || (REFCOUNT_DEBUGGING == REFCOUNT_DBG_ALL) |
|
|
|
#if (REFCOUNT_DEBUGGING == REFCOUNT_DBG_REFS) || (REFCOUNT_DEBUGGING == REFCOUNT_DBG_ALL) |
|
|
|
DEBUG_MSG("Inc %p %s: (xfer)", this, newTag); |
|
|
|
DEBUG_MSG("Inc %p %s: (xfer)", this, newTag); |
|
|
|