Skip to content

Commit

Permalink
Refs #10311. Make reference counter more extensible.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-kristjansson committed Jun 2, 2012
1 parent d6a4d9e commit 62d4299
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 6 additions & 4 deletions mythtv/libs/libmythbase/referencecounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ReferenceCounter::~ReferenceCounter(void)
}
}

void ReferenceCounter::IncrRef(void)
int ReferenceCounter::IncrRef(void)
{
int val = m_referenceCount.fetchAndAddRelease(1) + 1;

Expand All @@ -34,9 +34,11 @@ void ReferenceCounter::IncrRef(void)
LOG(VB_REFCOUNT, LOG_DEBUG, QString("(0x%2)::IncrRef() -> %3")
.arg(reinterpret_cast<intptr_t>(this),0,16).arg(val));
#endif

return val;
}

bool ReferenceCounter::DecrRef(void)
int ReferenceCounter::DecrRef(void)
{
int val = m_referenceCount.fetchAndAddRelaxed(-1) - 1;

Expand All @@ -51,8 +53,8 @@ bool ReferenceCounter::DecrRef(void)
if (0 == val)
{
delete this;
return true;
return val;
}

return false;
return val;
}
7 changes: 4 additions & 3 deletions mythtv/libs/libmythbase/referencecounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ class MBASE_PUBLIC ReferenceCounter
ReferenceCounter(const QString &debugName);

/// Increments reference count.
void IncrRef(void);
/// \return last reference count
virtual int IncrRef(void);

/// Decrements reference count and deletes on 0.
/// \return true if object is deleted
bool DecrRef(void);
/// \return last reference count, 0 if deleted
virtual int DecrRef(void);

protected:
/// Called on destruction, will warn if object deleted with
Expand Down

0 comments on commit 62d4299

Please sign in to comment.