diff options
Diffstat (limited to 'src/corelib/thread/qthreadpool.cpp')
-rw-r--r-- | src/corelib/thread/qthreadpool.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index ae584656fe..c7531111da 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -258,7 +258,7 @@ void QThreadPoolPrivate::startThread(QRunnable *runnable) /*! \internal - Helper function only to be called from waitForDone(int) + Helper function only to be called from waitForDone() Deletes all current threads. */ @@ -285,22 +285,17 @@ void QThreadPoolPrivate::reset() /*! \internal - Helper function only to be called from waitForDone(int) + Helper function only to be called from the public waitForDone() */ bool QThreadPoolPrivate::waitForDone(const QDeadlineTimer &timer) { + QMutexLocker locker(&mutex); while (!(queue.isEmpty() && activeThreads == 0) && !timer.hasExpired()) noActiveThreads.wait(&mutex, timer); - return queue.isEmpty() && activeThreads == 0; -} - -bool QThreadPoolPrivate::waitForDone(int msecs) -{ - QMutexLocker locker(&mutex); - QDeadlineTimer timer(msecs); - if (!waitForDone(timer)) + if (!queue.isEmpty() || activeThreads) return false; + reset(); // New jobs might have started during reset, but return anyway // as the active thread and task count did reach 0 once, and @@ -598,18 +593,17 @@ bool QThreadPool::tryStart(QRunnable *runnable) int QThreadPool::expiryTimeout() const { + using namespace std::chrono; Q_D(const QThreadPool); QMutexLocker locker(&d->mutex); - return d->expiryTimeout; + return duration_cast<milliseconds>(d->expiryTimeout).count(); } void QThreadPool::setExpiryTimeout(int expiryTimeout) { Q_D(QThreadPool); QMutexLocker locker(&d->mutex); - if (d->expiryTimeout == expiryTimeout) - return; - d->expiryTimeout = expiryTimeout; + d->expiryTimeout = std::chrono::milliseconds(expiryTimeout); } /*! \property QThreadPool::maxThreadCount @@ -808,15 +802,24 @@ void QThreadPool::startOnReservedThread(QRunnable *runnable) */ /*! + \fn bool QThreadPool::waitForDone(int msecs) Waits up to \a msecs milliseconds for all threads to exit and removes all threads from the thread pool. Returns \c true if all threads were removed; - otherwise it returns \c false. If \a msecs is -1 (the default), the timeout - is ignored (waits for the last thread to exit). + otherwise it returns \c false. If \a msecs is -1, this function waits for + the last thread to exit. +*/ + +/*! + \since 6.8 + + Waits until \a deadline expires for all threads to exit and removes all + threads from the thread pool. Returns \c true if all threads were removed; + otherwise it returns \c false. */ -bool QThreadPool::waitForDone(int msecs) +bool QThreadPool::waitForDone(QDeadlineTimer deadline) { Q_D(QThreadPool); - return d->waitForDone(msecs); + return d->waitForDone(deadline); } /*! |