summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qthreadpool.cpp27
-rw-r--r--src/corelib/thread/qthreadpool.h2
-rw-r--r--src/corelib/thread/qthreadpool_p.h1
3 files changed, 30 insertions, 0 deletions
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index a7d52f9652..bee6790705 100644
--- a/src/corelib/thread/qthreadpool.cpp
+++ b/src/corelib/thread/qthreadpool.cpp
@@ -308,6 +308,18 @@ bool QThreadPoolPrivate::waitForDone(int msecs)
return queue.isEmpty() && activeThreads == 0;
}
+void QThreadPoolPrivate::clear()
+{
+ QMutexLocker locker(&mutex);
+ for (QList<QPair<QRunnable *, int> >::const_iterator it = queue.constBegin();
+ it != queue.constEnd(); ++it) {
+ QRunnable* r = it->first;
+ if (r->autoDelete() && !--r->ref)
+ delete r;
+ }
+ queue.clear();
+}
+
/*!
\internal
Seaches for \a runnable in the queue, removes it from the queue and
@@ -609,6 +621,21 @@ bool QThreadPool::waitForDone(int msecs)
return rc;
}
+/*!
+ \since 5.2
+
+ Removes the runnables that are not yet started from the queue.
+ The runnables for which \l{QRunnable::autoDelete()}{runnable->autoDelete()}
+ returns true are deleted.
+
+ \sa start()
+*/
+void QThreadPool::clear()
+{
+ Q_D(QThreadPool);
+ d->clear();
+}
+
QT_END_NAMESPACE
#endif
diff --git a/src/corelib/thread/qthreadpool.h b/src/corelib/thread/qthreadpool.h
index ffc16dedbe..22a42c2272 100644
--- a/src/corelib/thread/qthreadpool.h
+++ b/src/corelib/thread/qthreadpool.h
@@ -83,6 +83,8 @@ public:
void releaseThread();
bool waitForDone(int msecs = -1);
+
+ void clear();
};
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qthreadpool_p.h b/src/corelib/thread/qthreadpool_p.h
index 754d754e74..ba77f7e57c 100644
--- a/src/corelib/thread/qthreadpool_p.h
+++ b/src/corelib/thread/qthreadpool_p.h
@@ -83,6 +83,7 @@ public:
void startThread(QRunnable *runnable = 0);
void reset();
bool waitForDone(int msecs);
+ void clear();
void stealRunnable(QRunnable *);
mutable QMutex mutex;