diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2012-11-04 21:21:31 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-08 15:11:56 +0100 |
commit | 17bea1689abc695d88f13cd15f73b0a59fcffdff (patch) | |
tree | 3686d3b4face64fb47fdb643a8bb73c887481101 /src/corelib/concurrent/qfutureinterface_p.h | |
parent | a4b5cd2893a5eef09d615340ae899f785de84858 (diff) | |
download | qt4-tools-17bea1689abc695d88f13cd15f73b0a59fcffdff.tar.gz |
QtConcurrent: Fix for leak in QFuture
To avoid leaking when converting a QFuture<T> to a QFuture<void> we need
to have a separate ref. counter for QFuture<T>. When the last QFuture<T>
goes out of scope, we need to clean out the result data.
backported from qt/qtbase commit 731ba8ed08f80644b403556638c7f6229e678ebe
Original commit by Christian Strømme
Task-number: QTBUG-27224
Change-Id: I0c6b525cf241b5c559a1bab4e0066cd4de556ea8
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
Diffstat (limited to 'src/corelib/concurrent/qfutureinterface_p.h')
-rw-r--r-- | src/corelib/concurrent/qfutureinterface_p.h | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/corelib/concurrent/qfutureinterface_p.h b/src/corelib/concurrent/qfutureinterface_p.h index 407c926137..8431b1ad37 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; |