Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/corelib/concurrent/qfutureinterface.cpp b/src/corelib/concurrent/qfutureinterface.cpp
- index 17bd5e2..3e4ab66 100644
- --- a/src/corelib/concurrent/qfutureinterface.cpp
- +++ b/src/corelib/concurrent/qfutureinterface.cpp
- @@ -419,6 +419,16 @@ bool QFutureInterfaceBase::referenceCountIsOne() const
- return d->refCount == 1;
- }
- +bool QFutureInterfaceBase::refT() const
- +{
- + return d->refCount.refT();
- +}
- +
- +bool QFutureInterfaceBase::derefT() const
- +{
- + return d->refCount.derefT();
- +}
- +
- QFutureInterfaceBasePrivate::QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState)
- : refCount(1), m_progressValue(0), m_progressMinimum(0), m_progressMaximum(0),
- state(initialState), pendingResults(0),
- diff --git a/src/corelib/concurrent/qfutureinterface.h b/src/corelib/concurrent/qfutureinterface.h
- index a31bcf1..4c5a26f 100644
- --- a/src/corelib/concurrent/qfutureinterface.h
- +++ b/src/corelib/concurrent/qfutureinterface.h
- @@ -132,6 +132,8 @@ public:
- protected:
- bool referenceCountIsOne() const;
- + bool refT() const;
- + bool derefT() const;
- public:
- #ifndef QFUTURE_TEST
- @@ -150,13 +152,17 @@ class QFutureInterface : public QFutureInterfaceBase
- public:
- QFutureInterface(State initialState = NoState)
- : QFutureInterfaceBase(initialState)
- - { }
- + {
- + refT();
- + }
- QFutureInterface(const QFutureInterface &other)
- : QFutureInterfaceBase(other)
- - { }
- + {
- + refT();
- + }
- ~QFutureInterface()
- {
- - if (referenceCountIsOne())
- + if (!derefT())
- resultStore().clear();
- }
- @@ -165,7 +171,8 @@ public:
- QFutureInterface &operator=(const QFutureInterface &other)
- {
- - if (referenceCountIsOne())
- + other.refT();
- + if (!derefT())
- resultStore().clear();
- QFutureInterfaceBase::operator=(other);
- return *this;
- diff --git a/src/corelib/concurrent/qfutureinterface_p.h b/src/corelib/concurrent/qfutureinterface_p.h
- index ea52621..3a34cda 100644
- --- a/src/corelib/concurrent/qfutureinterface_p.h
- +++ b/src/corelib/concurrent/qfutureinterface_p.h
- @@ -129,7 +129,31 @@ class QFutureInterfaceBasePrivate
- public:
- QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState);
- - QAtomicInt refCount;
- + // When the last QFuture<T> reference is removed, we need to make
- + // sure that data stored in the ResultStore is cleaned out.
- + // Since QFutureInterfaceBasePrivate can be shared between QFuture<T>
- + // and QFuture<void> objects, we use a separate ref. counter
- + // to keep track of QFuture<T> objects.
- + class RefCount
- + {
- + public:
- + inline RefCount(int r = 0, int rt = 0)
- + : m_refCount(r), m_refCountT(rt) {}
- + // Default ref counter for QFIBP
- + inline bool ref() { return m_refCount.ref(); }
- + inline bool deref() { return m_refCount.deref(); }
- + // Ref counter for type T
- + inline bool refT() { return m_refCountT.ref(); }
- + inline bool derefT() { return m_refCountT.deref(); }
- + inline operator int() const { return int(m_refCount); }
- + inline bool operator==(int value) const { return m_refCount == value; }
- +
- + private:
- + QAtomicInt m_refCount;
- + QAtomicInt m_refCountT;
- + };
- +
- + RefCount refCount;
- mutable QMutex m_mutex;
- QWaitCondition waitCondition;
- QList<QFutureCallOutInterface *> outputConnections;
- diff --git a/src/corelib/concurrent/qtconcurrentresultstore.h b/src/corelib/concurrent/qtconcurrentresultstore.h
- index fb5ef2f..81cd992 100644
- --- a/src/corelib/concurrent/qtconcurrentresultstore.h
- +++ b/src/corelib/concurrent/qtconcurrentresultstore.h
- @@ -177,7 +177,10 @@ public:
- int addResults(int index, const QVector<T> *results, int totalCount)
- {
- - return ResultStoreBase::addResults(index, new QVector<T>(*results), results->count(), totalCount);
- + if (m_filterMode && totalCount && !results->count())
- + return ResultStoreBase::addResults(index, 0, 0, totalCount);
- + else
- + return ResultStoreBase::addResults(index, new QVector<T>(*results), results->count(), totalCount);
- }
- int addCanceledResult(int index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement