Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refs #10311. Add additional debugging capabilities to ReferenceCounter.

The original ReferenceCounter class would print out the QObject's objectName().
I didn't implement this when I rewrote ReferenceCounter as a general purpose
reference counter. But having a name for an object does aid in debugging, this
reintroduces that idea but with a QString passed into the constructor. By
default this is not enabled, but if you need to debug reference counting
enabling it is just a matter of uncommenting a "//#define EXTRA_DEBUG" in
the header and recompiling.
  • Loading branch information...
commit f0bfe0f0737e918536b0dd8aca466c3d37df6032 1 parent 671017f
daniel-kristjansson daniel-kristjansson authored
9 mythtv/libs/libmythbase/mythcommandlineparser.cpp
View
@@ -143,7 +143,8 @@ const char* NamedOptType(int type)
*/
CommandLineArg::CommandLineArg(QString name, QVariant::Type type,
QVariant def, QString help, QString longhelp) :
- ReferenceCounter(), m_given(false), m_converted(false), m_name(name),
+ ReferenceCounter(QString("CommandLineArg:%1").arg(name)),
+ m_given(false), m_converted(false), m_name(name),
m_group(""), m_deprecated(""), m_removed(""), m_removedversion(""),
m_type(type), m_default(def), m_help(help), m_longhelp(longhelp)
{
@@ -159,7 +160,8 @@ CommandLineArg::CommandLineArg(QString name, QVariant::Type type,
* supplied directly on the command line.
*/
CommandLineArg::CommandLineArg(QString name, QVariant::Type type, QVariant def)
- : ReferenceCounter(), m_given(false), m_converted(false), m_name(name),
+ : ReferenceCounter(QString("CommandLineArg:%1").arg(name)),
+ m_given(false), m_converted(false), m_name(name),
m_group(""), m_deprecated(""), m_removed(""), m_removedversion(""),
m_type(type), m_default(def)
{
@@ -176,7 +178,8 @@ CommandLineArg::CommandLineArg(QString name, QVariant::Type type, QVariant def)
* name prior to parsing inputs.
*/
CommandLineArg::CommandLineArg(QString name) :
- ReferenceCounter(), m_given(false), m_converted(false), m_name(name),
+ ReferenceCounter(QString("CommandLineArg:%1").arg(name)),
+ m_given(false), m_converted(false), m_name(name),
m_deprecated(""), m_removed(""), m_removedversion(""),
m_type(QVariant::Invalid)
{
2  mythtv/libs/libmythbase/mythversion.h
View
@@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins.
-#define MYTH_BINARY_VERSION "0.26.20120528-1"
+#define MYTH_BINARY_VERSION "0.26.20120531-1"
/** \brief Increment this whenever the MythTV network protocol changes.
*
22 mythtv/libs/libmythbase/referencecounter.cpp
View
@@ -1,11 +1,17 @@
// -*- Mode: c++ -*-
#include <QString>
+
#include "referencecounter.h"
#include "mythlogging.h"
-ReferenceCounter::ReferenceCounter(void) : m_referenceCount(1)
+ReferenceCounter::ReferenceCounter(const QString &debugName) :
+#ifdef EXTRA_DEBUG
+ m_debugName(debugName),
+#endif
+ m_referenceCount(1)
{
+ (void) debugName;
}
ReferenceCounter::~ReferenceCounter(void)
@@ -19,18 +25,28 @@ ReferenceCounter::~ReferenceCounter(void)
void ReferenceCounter::IncrRef(void)
{
- int val = m_referenceCount.fetchAndAddRelease(1);
+ int val = m_referenceCount.fetchAndAddRelease(1) + 1;
+#ifdef EXTRA_DEBUG
+ LOG(VB_REFCOUNT, LOG_DEBUG, QString("%1(0x%2)::IncrRef() -> %3")
+ .arg(m_debugName).arg(reinterpret_cast<intptr_t>(this),0,16).arg(val));
+#else
LOG(VB_REFCOUNT, LOG_DEBUG, QString("(0x%2)::IncrRef() -> %3")
.arg(reinterpret_cast<intptr_t>(this),0,16).arg(val));
+#endif
}
bool ReferenceCounter::DecrRef(void)
{
- int val = m_referenceCount.fetchAndAddRelaxed(-1);
+ int val = m_referenceCount.fetchAndAddRelaxed(-1) - 1;
+#ifdef EXTRA_DEBUG
+ LOG(VB_REFCOUNT, LOG_DEBUG, QString("%1(0x%2)::DecrRef() -> %3")
+ .arg(m_debugName).arg(reinterpret_cast<intptr_t>(this),0,16).arg(val));
+#else
LOG(VB_REFCOUNT, LOG_DEBUG, QString("(0x%2)::DecrRef() -> %3")
.arg(reinterpret_cast<intptr_t>(this),0,16).arg(val));
Jean-Yves Avenard Collaborator

This is wrong..
It should be :
LOG(VB_REFCOUNT, LOG_DEBUG, QString("(0x%1)::DecrRef() -> %2")
.arg(reinterpret_cast(this),0,16).arg(val));

and same for all the other line of this type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+#endif
if (0 == val)
{
15 mythtv/libs/libmythbase/referencecounter.h
View
@@ -3,7 +3,17 @@
#ifndef MYTHREFCOUNT_H_
#define MYTHREFCOUNT_H_
+// Uncomment this line for more useful reference counting debugging
+//#define EXTRA_DEBUG
+
#include <QAtomicInt>
+
+#ifdef EXTRA_DEBUG
+#include <QString>
+#else
+class QString;
+#endif
+
#include "mythbaseexp.h"
/** \brief General purpose reference counter.
@@ -15,7 +25,7 @@ class MBASE_PUBLIC ReferenceCounter
{
public:
/// Creates reference counter with an initial value of 1.
- ReferenceCounter(void);
+ ReferenceCounter(const QString &debugName);
/// Increments reference count.
void IncrRef(void);
@@ -30,6 +40,9 @@ class MBASE_PUBLIC ReferenceCounter
virtual ~ReferenceCounter(void);
private:
+#ifdef EXTRA_DEBUG
+ const QString m_debugName;
+#endif
QAtomicInt m_referenceCount;
};
5 mythtv/libs/libmythprotoserver/requesthandler/fileserverutil.cpp
View
@@ -17,12 +17,13 @@
#include "programinfo.h"
DeleteHandler::DeleteHandler(void) :
- ReferenceCounter(), m_fd(-1), m_size(0)
+ ReferenceCounter("DeleteHandler"), m_fd(-1), m_size(0)
{
}
DeleteHandler::DeleteHandler(QString filename) :
- ReferenceCounter(), m_path(filename), m_fd(-1), m_size(0)
+ ReferenceCounter(QString("DeleteHandler:%1").arg(filename)),
+ m_path(filename), m_fd(-1), m_size(0)
{
}
3  mythtv/libs/libmythprotoserver/sockethandler.cpp
View
@@ -8,7 +8,8 @@ using namespace std;
SocketHandler::SocketHandler(MythSocket *sock, MythSocketManager *parent,
QString hostname) :
- ReferenceCounter(), m_blockShutdown(false), m_standardEvents(false),
+ ReferenceCounter("SocketHandler"),
+ m_blockShutdown(false), m_standardEvents(false),
m_systemEvents(false), m_socket(sock), m_parent(parent),
m_hostname(hostname)
{
2  mythtv/libs/libmythupnp/ssdpcache.cpp
View
@@ -27,7 +27,7 @@ int SSDPCacheEntries::g_nAllocated = 0; // Debugging only
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-SSDPCacheEntries::SSDPCacheEntries()
+SSDPCacheEntries::SSDPCacheEntries() : ReferenceCounter("SSDPCacheEntries")
{
g_nAllocated++; // Should be atomic increment
}
2  mythtv/libs/libmythupnp/taskqueue.cpp
View
@@ -38,7 +38,7 @@ long Task::m_nTaskCount = 0;
//
/////////////////////////////////////////////////////////////////////////////
-Task::Task()
+Task::Task(const QString &debugName) : ReferenceCounter(debugName)
{
m_nTaskId = m_nTaskCount++;
}
2  mythtv/libs/libmythupnp/taskqueue.h
View
@@ -65,7 +65,7 @@ class Task : public ReferenceCounter
public:
- Task();
+ Task(const QString &debugName);
long Id() const { return( m_nTaskId ); }
4 mythtv/libs/libmythupnp/upnpdevice.h
View
@@ -236,7 +236,9 @@ class UPNP_PUBLIC DeviceLocation : public ReferenceCounter
DeviceLocation( const QString &sURI,
const QString &sUSN,
const QString &sLocation,
- TaskTime ttExpires ) : m_pDeviceDesc( NULL ),
+ TaskTime ttExpires ) : ReferenceCounter(
+ "DeviceLocation" ),
+ m_pDeviceDesc( NULL ),
m_sURI ( sURI ),
m_sUSN ( sUSN ),
m_sLocation ( sLocation ),
2  mythtv/libs/libmythupnp/upnptaskcache.h
View
@@ -39,7 +39,7 @@ class SSDPCacheTask : public Task
public:
- SSDPCacheTask()
+ SSDPCacheTask() : Task("SSDPCacheTask")
{
m_nExecuteCount = 0;
m_nInterval = 1000 *
3  mythtv/libs/libmythupnp/upnptaskevent.cpp
View
@@ -27,7 +27,8 @@
UPnpEventTask::UPnpEventTask( QHostAddress peerAddress,
int nPeerPort,
- QByteArray *pPayload )
+ QByteArray *pPayload ) :
+ Task("UPnpEventTask")
{
m_PeerAddress = peerAddress;
m_nPeerPort = nPeerPort;
3  mythtv/libs/libmythupnp/upnptasknotify.cpp
View
@@ -37,7 +37,8 @@
//
/////////////////////////////////////////////////////////////////////////////
-UPnpNotifyTask::UPnpNotifyTask( int nServicePort )
+UPnpNotifyTask::UPnpNotifyTask( int nServicePort ) :
+ Task("UPnpNotifyTask")
{
m_nServicePort = nServicePort;
m_eNTS = NTS_alive;
3  mythtv/libs/libmythupnp/upnptasksearch.cpp
View
@@ -38,7 +38,8 @@ UPnpSearchTask::UPnpSearchTask( int nServicePort,
QHostAddress peerAddress,
int nPeerPort,
QString sST,
- QString sUDN )
+ QString sUDN ) :
+ Task("UPnpSearchTask")
{
m_PeerAddress = peerAddress;
m_nPeerPort = nPeerPort;
Jean-Yves Avenard

This is wrong..
It should be :
LOG(VB_REFCOUNT, LOG_DEBUG, QString("(0x%1)::DecrRef() -> %2")
.arg(reinterpret_cast(this),0,16).arg(val));

and same for all the other line of this type

Please sign in to comment.
Something went wrong with that request. Please try again.