summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qfutureinterface.h2
-rw-r--r--src/corelib/thread/qorderedmutexlocker_p.h41
-rw-r--r--src/corelib/thread/qresultstore.cpp1
-rw-r--r--src/corelib/thread/qresultstore.h7
4 files changed, 50 insertions, 1 deletions
diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h
index bcdae24833..e4cc46e929 100644
--- a/src/corelib/thread/qfutureinterface.h
+++ b/src/corelib/thread/qfutureinterface.h
@@ -201,7 +201,7 @@ inline void QFutureInterface<T>::reportResult(const T *result, int index)
if (store.filterMode()) {
const int resultCountBefore = store.count();
store.addResult<T>(index, result);
- this->reportResultsReady(resultCountBefore, resultCountBefore + store.count());
+ this->reportResultsReady(resultCountBefore, store.count());
} else {
const int insertIndex = store.addResult<T>(index, result);
this->reportResultsReady(insertIndex, insertIndex + 1);
diff --git a/src/corelib/thread/qorderedmutexlocker_p.h b/src/corelib/thread/qorderedmutexlocker_p.h
index 83edfd5879..9a9aaefa02 100644
--- a/src/corelib/thread/qorderedmutexlocker_p.h
+++ b/src/corelib/thread/qorderedmutexlocker_p.h
@@ -74,6 +74,28 @@ public:
{
relock();
}
+
+ Q_DISABLE_COPY(QOrderedMutexLocker)
+
+ void swap(QOrderedMutexLocker &other) noexcept
+ {
+ qSwap(this->mtx1, other.mtx1);
+ qSwap(this->mtx2, other.mtx2);
+ qSwap(this->locked, other.locked);
+ }
+
+ QOrderedMutexLocker &operator=(QOrderedMutexLocker &&other) noexcept {
+ QOrderedMutexLocker moved(std::move(other));
+ swap(moved);
+ return *this;
+ }
+
+ QOrderedMutexLocker(QOrderedMutexLocker &&other) noexcept
+ : mtx1(std::exchange(other.mtx1, nullptr))
+ , mtx2(std::exchange(other.mtx2, nullptr))
+ , locked(std::exchange(other.locked, false))
+ {}
+
~QOrderedMutexLocker()
{
unlock();
@@ -88,6 +110,21 @@ public:
}
}
+ /*!
+ \internal
+ Can be called if the mutexes have been unlocked manually, and sets the
+ state of the QOrderedMutexLocker to unlocked.
+ The caller is expected to have unlocked both of them if they
+ are not the same. Calling this method when the QOrderedMutexLocker is
+ unlocked or when the provided mutexes have not actually been unlocked is
+ UB.
+ */
+ void dismiss()
+ {
+ Q_ASSERT(locked);
+ locked = false;
+ }
+
void unlock()
{
if (locked) {
@@ -153,11 +190,15 @@ private:
class QOrderedMutexLocker
{
public:
+ Q_DISABLE_COPY(QOrderedMutexLocker)
QOrderedMutexLocker(QBasicMutex *, QBasicMutex *) {}
+ QOrderedMutexLocker(QOrderedMutexLocker &&) = default;
+ QOrderedMutexLocker& operator=(QOrderedMutexLocker &&other) = default;
~QOrderedMutexLocker() {}
void relock() {}
void unlock() {}
+ void dismiss() {}
static bool relock(QBasicMutex *, QBasicMutex *) { return false; }
};
diff --git a/src/corelib/thread/qresultstore.cpp b/src/corelib/thread/qresultstore.cpp
index 0b82b938e1..069e2a7a07 100644
--- a/src/corelib/thread/qresultstore.cpp
+++ b/src/corelib/thread/qresultstore.cpp
@@ -185,6 +185,7 @@ int ResultStoreBase::addResult(int index, const void *result)
int ResultStoreBase::addResults(int index, const void *results, int vectorSize, int totalCount)
{
if (m_filterMode == false || vectorSize == totalCount) {
+ Q_ASSERT(vectorSize != 0);
ResultItem resultItem(results, vectorSize);
return insertResultItem(index, resultItem);
} else {
diff --git a/src/corelib/thread/qresultstore.h b/src/corelib/thread/qresultstore.h
index 7a65089396..f58341cdf0 100644
--- a/src/corelib/thread/qresultstore.h
+++ b/src/corelib/thread/qresultstore.h
@@ -151,12 +151,19 @@ public:
template <typename T>
int addResults(int index, const QVector<T> *results)
{
+ if (results->empty()) // reject if results are empty
+ return -1;
+
return addResults(index, new QVector<T>(*results), results->count(), results->count());
}
template <typename T>
int addResults(int index, const QVector<T> *results, int totalCount)
{
+ // reject if results are empty, and nothing is filtered away
+ if ((m_filterMode == false || results->count() == totalCount) && results->empty())
+ return -1;
+
if (m_filterMode == true && results->count() != totalCount && 0 == results->count())
return addResults(index, nullptr, 0, totalCount);
else