Cleanup reference counting in internal::Base class (qtconcurrent)
It is better to use QSharedData and QExplicitlySharedDataPointer then doing manual ref counting. Change-Id: I5674046141701bd48a53415ab96fcb6b538e79e6 Reviewed-on: http://codereview.qt.nokia.com/1440 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
This commit is contained in:
parent
d1f080138a
commit
12d9436522
@ -40,6 +40,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "qtconcurrentexception.h"
|
#include "qtconcurrentexception.h"
|
||||||
|
#include "QtCore/qshareddata.h"
|
||||||
|
|
||||||
#ifndef QT_NO_QFUTURE
|
#ifndef QT_NO_QFUTURE
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
@ -141,15 +142,14 @@ Exception *UnhandledException::clone() const
|
|||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
class Base
|
class Base : public QSharedData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Base(Exception *exception)
|
Base(Exception *exception)
|
||||||
: exception(exception), refCount(1), hasThrown(false) { }
|
: exception(exception), hasThrown(false) { }
|
||||||
~Base() { delete exception; }
|
~Base() { delete exception; }
|
||||||
|
|
||||||
Exception *exception;
|
Exception *exception;
|
||||||
QAtomicInt refCount;
|
|
||||||
bool hasThrown;
|
bool hasThrown;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -158,27 +158,15 @@ ExceptionHolder::ExceptionHolder(Exception *exception)
|
|||||||
|
|
||||||
ExceptionHolder::ExceptionHolder(const ExceptionHolder &other)
|
ExceptionHolder::ExceptionHolder(const ExceptionHolder &other)
|
||||||
: base(other.base)
|
: base(other.base)
|
||||||
{
|
{}
|
||||||
base->refCount.ref();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExceptionHolder::operator=(const ExceptionHolder &other)
|
void ExceptionHolder::operator=(const ExceptionHolder &other)
|
||||||
{
|
{
|
||||||
if (base == other.base)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (base->refCount.deref() == false)
|
|
||||||
delete base;
|
|
||||||
|
|
||||||
base = other.base;
|
base = other.base;
|
||||||
base->refCount.ref();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExceptionHolder::~ExceptionHolder()
|
ExceptionHolder::~ExceptionHolder()
|
||||||
{
|
{}
|
||||||
if (base->refCount.deref() == 0)
|
|
||||||
delete base;
|
|
||||||
}
|
|
||||||
|
|
||||||
Exception *ExceptionHolder::exception() const
|
Exception *ExceptionHolder::exception() const
|
||||||
{
|
{
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#ifndef QT_NO_QFUTURE
|
#ifndef QT_NO_QFUTURE
|
||||||
|
|
||||||
#include <QtCore/qatomic.h>
|
#include <QtCore/qatomic.h>
|
||||||
|
#include <QtCore/qshareddata.h>
|
||||||
|
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
# include <exception>
|
# include <exception>
|
||||||
@ -87,7 +88,7 @@ public:
|
|||||||
void operator=(const ExceptionHolder &other);
|
void operator=(const ExceptionHolder &other);
|
||||||
~ExceptionHolder();
|
~ExceptionHolder();
|
||||||
Exception *exception() const;
|
Exception *exception() const;
|
||||||
Base *base;
|
QExplicitlySharedDataPointer<Base> base;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Q_CORE_EXPORT ExceptionStore
|
class Q_CORE_EXPORT ExceptionStore
|
||||||
|
Loading…
x
Reference in New Issue
Block a user