MythTV master
referencecounter.h
Go to the documentation of this file.
1// -*- Mode: c++ -*-
2
3#ifndef MYTHREFCOUNT_H_
4#define MYTHREFCOUNT_H_
5
6// Uncomment this line for more useful reference counting debugging
7//#define EXTRA_DEBUG
8// Uncomment the DEBUG define lines in referencecounter.cpp for
9// even more debugging.
10
11#include <QAtomicInt>
12
13#ifdef EXTRA_DEBUG
14#include <QString>
15#else
16class QString;
17#endif
18
19#include "mythbaseexp.h"
20
27{
28 public:
30 explicit ReferenceCounter(const QString &debugName, bool logDebug = true);
31
34 virtual int IncrRef(void);
35
38 virtual int DecrRef(void);
39
41 static void PrintDebug(void);
42 protected:
45 virtual ~ReferenceCounter(void);
46
47 protected:
48#ifdef EXTRA_DEBUG
49 const QString m_debugName;
50#endif
57 QAtomicInt m_referenceCount {1};
58};
59
67{
68 public:
69 explicit ReferenceLocker(ReferenceCounter *counter) : m_counter(counter) { }
71 {
72 if (m_counter)
73 m_counter->DecrRef();
74 }
75 private:
76 ReferenceCounter *m_counter {nullptr};
77};
78
79#endif
General purpose reference counter.
bool m_logDebug
This is used to suppress creating LoggingItem classes for LoggingItem reference count changes.
This decrements the reference on destruction.
ReferenceLocker(ReferenceCounter *counter)
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15