Advertisement
orgads

QTBUG-27224 patch for 4.8.3

Nov 13th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.27 KB | None | 0 0
  1. diff --git a/src/corelib/concurrent/qfutureinterface.cpp b/src/corelib/concurrent/qfutureinterface.cpp
  2. index 17bd5e2..3e4ab66 100644
  3. --- a/src/corelib/concurrent/qfutureinterface.cpp
  4. +++ b/src/corelib/concurrent/qfutureinterface.cpp
  5. @@ -419,6 +419,16 @@ bool QFutureInterfaceBase::referenceCountIsOne() const
  6.      return d->refCount == 1;
  7.  }
  8.  
  9. +bool QFutureInterfaceBase::refT() const
  10. +{
  11. +    return d->refCount.refT();
  12. +}
  13. +
  14. +bool QFutureInterfaceBase::derefT() const
  15. +{
  16. +    return d->refCount.derefT();
  17. +}
  18. +
  19.  QFutureInterfaceBasePrivate::QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState)
  20.      : refCount(1), m_progressValue(0), m_progressMinimum(0), m_progressMaximum(0),
  21.        state(initialState), pendingResults(0),
  22. diff --git a/src/corelib/concurrent/qfutureinterface.h b/src/corelib/concurrent/qfutureinterface.h
  23. index a31bcf1..4c5a26f 100644
  24. --- a/src/corelib/concurrent/qfutureinterface.h
  25. +++ b/src/corelib/concurrent/qfutureinterface.h
  26. @@ -132,6 +132,8 @@ public:
  27.  
  28.  protected:
  29.      bool referenceCountIsOne() const;
  30. +    bool refT() const;
  31. +    bool derefT() const;
  32.  public:
  33.  
  34.  #ifndef QFUTURE_TEST
  35. @@ -150,13 +152,17 @@ class QFutureInterface : public QFutureInterfaceBase
  36.  public:
  37.      QFutureInterface(State initialState = NoState)
  38.          : QFutureInterfaceBase(initialState)
  39. -    { }
  40. +    {
  41. +        refT();
  42. +    }
  43.      QFutureInterface(const QFutureInterface &other)
  44.          : QFutureInterfaceBase(other)
  45. -    { }
  46. +    {
  47. +        refT();
  48. +    }
  49.      ~QFutureInterface()
  50.      {
  51. -        if (referenceCountIsOne())
  52. +        if (!derefT())
  53.              resultStore().clear();
  54.      }
  55.  
  56. @@ -165,7 +171,8 @@ public:
  57.  
  58.      QFutureInterface &operator=(const QFutureInterface &other)
  59.      {
  60. -        if (referenceCountIsOne())
  61. +        other.refT();
  62. +        if (!derefT())
  63.              resultStore().clear();
  64.          QFutureInterfaceBase::operator=(other);
  65.          return *this;
  66. diff --git a/src/corelib/concurrent/qfutureinterface_p.h b/src/corelib/concurrent/qfutureinterface_p.h
  67. index ea52621..3a34cda 100644
  68. --- a/src/corelib/concurrent/qfutureinterface_p.h
  69. +++ b/src/corelib/concurrent/qfutureinterface_p.h
  70. @@ -129,7 +129,31 @@ class QFutureInterfaceBasePrivate
  71.  public:
  72.      QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState);
  73.  
  74. -    QAtomicInt refCount;
  75. +    // When the last QFuture<T> reference is removed, we need to make
  76. +    // sure that data stored in the ResultStore is cleaned out.
  77. +    // Since QFutureInterfaceBasePrivate can be shared between QFuture<T>
  78. +    // and QFuture<void> objects, we use a separate ref. counter
  79. +    // to keep track of QFuture<T> objects.
  80. +    class RefCount
  81. +    {
  82. +    public:
  83. +        inline RefCount(int r = 0, int rt = 0)
  84. +            : m_refCount(r), m_refCountT(rt) {}
  85. +        // Default ref counter for QFIBP
  86. +        inline bool ref() { return m_refCount.ref(); }
  87. +        inline bool deref() { return m_refCount.deref(); }
  88. +        // Ref counter for type T
  89. +        inline bool refT() { return m_refCountT.ref(); }
  90. +        inline bool derefT() { return m_refCountT.deref(); }
  91. +        inline operator int() const { return int(m_refCount); }
  92. +        inline bool operator==(int value) const { return m_refCount == value; }
  93. +
  94. +    private:
  95. +        QAtomicInt m_refCount;
  96. +        QAtomicInt m_refCountT;
  97. +    };
  98. +
  99. +    RefCount refCount;
  100.      mutable QMutex m_mutex;
  101.      QWaitCondition waitCondition;
  102.      QList<QFutureCallOutInterface *> outputConnections;
  103. diff --git a/src/corelib/concurrent/qtconcurrentresultstore.h b/src/corelib/concurrent/qtconcurrentresultstore.h
  104. index fb5ef2f..81cd992 100644
  105. --- a/src/corelib/concurrent/qtconcurrentresultstore.h
  106. +++ b/src/corelib/concurrent/qtconcurrentresultstore.h
  107. @@ -177,7 +177,10 @@ public:
  108.  
  109.      int addResults(int index, const QVector<T> *results, int totalCount)
  110.      {
  111. -        return ResultStoreBase::addResults(index, new QVector<T>(*results), results->count(), totalCount);
  112. +        if (m_filterMode && totalCount && !results->count())
  113. +            return ResultStoreBase::addResults(index, 0, 0, totalCount);
  114. +        else
  115. +            return ResultStoreBase::addResults(index, new QVector<T>(*results), results->count(), totalCount);
  116.      }
  117.  
  118.      int addCanceledResult(int index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement