aboutsummaryrefslogtreecommitdiffstats
path: root/src/utility/smartPtr.cpp
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2007-05-22 19:25:59 +0000
committerVincent Richard <[email protected]>2007-05-22 19:25:59 +0000
commit8c6ba0e0587b4b28044385da90af408d72a0da01 (patch)
tree9a5ff41766dc96c9808bccc1777b305ed4d78022 /src/utility/smartPtr.cpp
parentFail if GNU TLS or GNU SASL dev packages are required but not installed. (diff)
downloadvmime-8c6ba0e0587b4b28044385da90af408d72a0da01.tar.gz
vmime-8c6ba0e0587b4b28044385da90af408d72a0da01.zip
Fixed bug #1721186: thread-safe reference counting.
Diffstat (limited to 'src/utility/smartPtr.cpp')
-rw-r--r--src/utility/smartPtr.cpp131
1 files changed, 3 insertions, 128 deletions
diff --git a/src/utility/smartPtr.cpp b/src/utility/smartPtr.cpp
index 16249df8..08a8f57c 100644
--- a/src/utility/smartPtr.cpp
+++ b/src/utility/smartPtr.cpp
@@ -29,135 +29,10 @@ namespace vmime {
namespace utility {
-// refManager
-
-refManager::refManager(object* obj)
- : m_object(obj), m_strongCount(1), m_weakCount(1)
-{
-}
-
-
-refManager::~refManager()
-{
-}
-
-
-const bool refManager::addStrong()
-{
- if (m_strongCount <= 0)
- return false;
-
- m_strongCount.increment();
- m_weakCount.increment();
-
- return true;
-}
-
-
-void refManager::releaseStrong()
-{
- m_strongCount.decrement();
-
- if (m_strongCount.compareExchange(0, -424242) == 0) // prevent from adding strong refs later
- deleteObject();
-
- releaseWeak();
-}
-
-
-void refManager::addWeak()
-{
- m_weakCount.increment();
-}
-
-
-void refManager::releaseWeak()
-{
- if (m_weakCount.decrement() == 0)
- deleteManager();
-}
-
-
-object* refManager::getObject()
-{
- return m_object;
-}
-
-
-void refManager::deleteManager()
-{
- delete this;
-}
-
-
-void refManager::deleteObject()
-{
- try
- {
- m_object->setRefManager(0);
- delete m_object;
- }
- catch (...)
- {
- // Exception in destructor
- }
-
- m_object = 0;
-}
-
-
-const long refManager::getStrongRefCount() const
-{
- return m_strongCount;
-}
-
-
-const long refManager::getWeakRefCount() const
-{
- return m_weakCount;
-}
-
-
-
-// refCounter
-
-refCounter::refCounter(const long initialValue)
- : m_value(initialValue)
-{
-}
-
-
-refCounter::~refCounter()
-{
-}
-
-
-const long refCounter::increment()
-{
- return ++m_value;
-}
-
-
-const long refCounter::decrement()
-{
- return --m_value;
-}
-
-
-const long refCounter::compareExchange(const long compare, const long exchangeWith)
-{
- const int prev = m_value;
-
- if (m_value == compare)
- m_value = exchangeWith;
-
- return prev;
-}
-
-
-refCounter::operator long() const
+void refManager::deleteObjectImpl(object* obj)
{
- return m_value;
+ obj->setRefManager(0);
+ delete obj;
}