mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 11:19:10 +00:00
Fix leak check race condition, and remove an unintentional circular ref
This commit is contained in:
@ -54,6 +54,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
|
|
||||||
#if (REFCOUNT_DEBUGGING == REFCOUNT_DBG_LEAKS) || (REFCOUNT_DEBUGGING == REFCOUNT_DBG_ALL)
|
#if (REFCOUNT_DEBUGGING == REFCOUNT_DBG_LEAKS) || (REFCOUNT_DEBUGGING == REFCOUNT_DBG_ALL)
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <mutex>
|
||||||
#include "plFormat.h"
|
#include "plFormat.h"
|
||||||
#include "hsWindows.h"
|
#include "hsWindows.h"
|
||||||
|
|
||||||
@ -61,12 +62,15 @@ template <class _RefType>
|
|||||||
struct _RefCountLeakCheck
|
struct _RefCountLeakCheck
|
||||||
{
|
{
|
||||||
std::unordered_set<_RefType *> m_refs;
|
std::unordered_set<_RefType *> m_refs;
|
||||||
unsigned s_added, s_removed;
|
unsigned m_added, m_removed;
|
||||||
|
std::mutex m_mutex;
|
||||||
|
|
||||||
~_RefCountLeakCheck()
|
~_RefCountLeakCheck()
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
OutputDebugString(plFormat("Refs tracked: {} created, {} destroyed\n",
|
OutputDebugString(plFormat("Refs tracked: {} created, {} destroyed\n",
|
||||||
s_added, s_removed).c_str());
|
m_added, m_removed).c_str());
|
||||||
if (m_refs.empty())
|
if (m_refs.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -86,14 +90,16 @@ struct _RefCountLeakCheck
|
|||||||
static void add(_RefType *node)
|
static void add(_RefType *node)
|
||||||
{
|
{
|
||||||
_RefCountLeakCheck<_RefType> *p = _instance();
|
_RefCountLeakCheck<_RefType> *p = _instance();
|
||||||
++p->s_added;
|
std::lock_guard<std::mutex> lock(p->m_mutex);
|
||||||
|
++p->m_added;
|
||||||
p->m_refs.insert(node);
|
p->m_refs.insert(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void del(_RefType *node)
|
static void del(_RefType *node)
|
||||||
{
|
{
|
||||||
_RefCountLeakCheck<_RefType> *p = _instance();
|
_RefCountLeakCheck<_RefType> *p = _instance();
|
||||||
++p->s_removed;
|
std::lock_guard<std::mutex> lock(p->m_mutex);
|
||||||
|
++p->m_removed;
|
||||||
p->m_refs.erase(node);
|
p->m_refs.erase(node);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -104,7 +104,7 @@ struct RelVaultNodeLink : THashKeyVal<unsigned> {
|
|||||||
|
|
||||||
|
|
||||||
struct IRelVaultNode {
|
struct IRelVaultNode {
|
||||||
hsRef<RelVaultNode> node;
|
RelVaultNode * node; // MUST be a weak ref!
|
||||||
|
|
||||||
HASHTABLEDECL(
|
HASHTABLEDECL(
|
||||||
RelVaultNodeLink,
|
RelVaultNodeLink,
|
||||||
|
Reference in New Issue
Block a user