16 #include <QReadWriteLock> 18 #include "../libmythui/mythimage.h" 19 static QReadWriteLock leakLock;
22 LeakInfo() : refCount(0) {}
23 LeakInfo(
const QString &n) :
name(n), refCount(1) {}
27 static QMap<ReferenceCounter*,LeakInfo> leakMap;
30 QReadLocker locker(&leakLock);
31 QList<uint64_t> logType;
35 QMap<ReferenceCounter*,LeakInfo>::iterator it = leakMap.begin();
36 for (; it != leakMap.end(); ++it)
38 if ((*it).refCount.fetchAndAddOrdered(0) == 0)
40 if ((*it).name.startsWith(
"CommandLineArg"))
42 if (!it.key()->m_logDebug)
46 logType += (cnt) ? VB_GENERAL : VB_REFCOUNT;
47 logLines += QString(
"Leaked %1 reference counted objects").arg(cnt);
49 for (it = leakMap.begin(); it != leakMap.end(); ++it)
51 if ((*it).refCount.fetchAndAddOrdered(0) == 0)
53 if ((*it).name.startsWith(
"CommandLineArg"))
55 if (!it.key()->m_logDebug)
58 logType += VB_REFCOUNT;
60 QString(
" Leaked %1(0x%2) reference count %3")
62 .arg(reinterpret_cast<intptr_t>(it.key()),0,16)
68 for (
uint i = 0; i < (
uint)logType.size() && i < (
uint)logLines.size(); i++)
69 LOG(logType[i], LOG_INFO, logLines[i]);
77 m_debugName(debugName),
84 QWriteLocker locker(&leakLock);
85 leakMap[
this] = LeakInfo(debugName);
93 LOG(VB_GENERAL, LOG_ERR,
94 "Object deleted with non-zero or one reference count!");
97 QWriteLocker locker(&leakLock);
98 leakMap.erase(leakMap.find(
this));
109 LOG(VB_REFCOUNT, LOG_INFO, QString(
"%1(0x%2)::IncrRef() -> %3")
110 .arg(m_debugName).arg(reinterpret_cast<intptr_t>(
this),0,16)
113 LOG(VB_REFCOUNT, LOG_INFO, QString(
"(0x%2)::IncrRef() -> %3")
114 .arg(reinterpret_cast<intptr_t>(
this),0,16).arg(val));
119 QReadLocker locker(&leakLock);
120 leakMap[
this].refCount.fetchAndAddOrdered(1);
132 QReadLocker locker(&leakLock);
133 leakMap[
this].refCount.fetchAndAddOrdered(-1);
140 LOG(VB_REFCOUNT, LOG_INFO, QString(
"%1(0x%2)::DecrRef() -> %3")
141 .arg(m_debugName).arg(reinterpret_cast<intptr_t>(
this),0,16)
144 LOG(VB_REFCOUNT, LOG_INFO, QString(
"(0x%2)::DecrRef() -> %3")
145 .arg(reinterpret_cast<intptr_t>(
this),0,16).arg(val));
149 #ifdef NO_DELETE_DEBUG 152 LOG(VB_REFCOUNT, LOG_ERR, QString(
"(0x%2)::DecrRef() -> %3 !!!")
153 .arg(reinterpret_cast<intptr_t>(
this),0,16).arg(val));
QAtomicInt m_referenceCount
virtual int IncrRef(void)
Increments reference count.
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
static void PrintDebug(void)
Print out any leaks if that level of debugging is enabled.
ReferenceCounter(const QString &debugName, bool logDebug=true)
Creates reference counter with an initial value of 1.
#define LOG(_MASK_, _LEVEL_, _STRING_)
bool m_logDebug
This is used to suppress creating LoggingItem classes for LoggingItem reference count changes.
virtual ~ReferenceCounter(void)
Called on destruction, will warn if object deleted with references in place.