From 6c723ca289c2a3fc88a54f391b35e9cf892fd28b Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Wed, 3 Oct 2012 18:56:18 -0400 Subject: [PATCH] Fix some problems with our not so smart pointers. --- Core/src/Thread.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Core/src/Thread.cpp b/Core/src/Thread.cpp index 5b8aa8b..cb39052 100644 --- a/Core/src/Thread.cpp +++ b/Core/src/Thread.cpp @@ -21,14 +21,29 @@ TCThreadBase::TCThreadBase(const TCThreadBase &other) TCThreadBase &TCThreadBase::operator=(const TCThreadBase &other) { assert(m_Impl->GetReferenceCount() > 0); + + // We are no longer referencing this implementation... m_Impl->DecreaseReferenceCount(); + + // If we're the last ones to reference it, then it should be destroyed. + if(m_Impl->GetReferenceCount() <= 0) { + delete m_Impl; + m_Impl = 0; + } + + // Our implementation is now the same as the other. m_Impl = other.m_Impl; m_Impl->IncreaseReferenceCount(); } TCThreadBase::~TCThreadBase() { - if(m_Impl->GetReferenceCount() <= 1) { - assert(m_Impl->GetReferenceCount() >= 0); + + // We are no longer referencing this implementation... + m_Impl->DecreaseReferenceCount(); + + // If we're the last ones to reference it, then it should be destroyed. + if(m_Impl->GetReferenceCount() <= 0) { + assert(m_Impl->GetReferenceCount() == 0); delete m_Impl; } }