summaryrefslogtreecommitdiffstats
path: root/src/corelib/concurrent
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@nokia.com>2010-02-22 13:53:52 (GMT)
committerPierre Rossi <pierre.rossi@nokia.com>2010-03-31 14:33:21 (GMT)
commita0df2ac07c75882618b40657e1485dda3204880e (patch)
tree76ca0fc16b272b8dd6ddd493ab37a3b0a2a61d13 /src/corelib/concurrent
parent524ee26ed5202aa45d337a0a852a2eb2896ac205 (diff)
downloadQt-a0df2ac07c75882618b40657e1485dda3204880e.zip
Qt-a0df2ac07c75882618b40657e1485dda3204880e.tar.gz
Qt-a0df2ac07c75882618b40657e1485dda3204880e.tar.bz2
adds a timeout option to QThreadPool::waitForDone();
Task-number: QTBUG-2695 Reviewed-by: Benjamin Poulain
Diffstat (limited to 'src/corelib/concurrent')
-rw-r--r--src/corelib/concurrent/qthreadpool.cpp18
-rw-r--r--src/corelib/concurrent/qthreadpool.h2
-rw-r--r--src/corelib/concurrent/qthreadpool_p.h2
3 files changed, 15 insertions, 7 deletions
diff --git a/src/corelib/concurrent/qthreadpool.cpp b/src/corelib/concurrent/qthreadpool.cpp
index 9e4189e..a4057f1 100644
--- a/src/corelib/concurrent/qthreadpool.cpp
+++ b/src/corelib/concurrent/qthreadpool.cpp
@@ -41,6 +41,7 @@
#include "qthreadpool.h"
#include "qthreadpool_p.h"
+#include "qelapsedtimer.h"
#ifndef QT_NO_THREAD
@@ -288,11 +289,18 @@ void QThreadPoolPrivate::reset()
isExiting = false;
}
-void QThreadPoolPrivate::waitForDone()
+void QThreadPoolPrivate::waitForDone(int msecs)
{
QMutexLocker locker(&mutex);
- while (!(queue.isEmpty() && activeThreads == 0))
- noActiveThreads.wait(locker.mutex());
+ if (msecs < 0){
+ while (!(queue.isEmpty() && activeThreads == 0))
+ noActiveThreads.wait(locker.mutex());
+ } else {
+ QElapsedTimer timer;
+ timer.start();
+ while (!(queue.isEmpty() && activeThreads == 0) && (timer.elapsed() < msecs))
+ noActiveThreads.wait(locker.mutex(), msecs - timer.elapsed());
+ }
}
/*! \internal
@@ -610,10 +618,10 @@ void QThreadPool::releaseThread()
/*!
Waits for each thread to exit and removes all threads from the thread pool.
*/
-void QThreadPool::waitForDone()
+void QThreadPool::waitForDone(int msecs)
{
Q_D(QThreadPool);
- d->waitForDone();
+ d->waitForDone(msecs);
d->reset();
}
diff --git a/src/corelib/concurrent/qthreadpool.h b/src/corelib/concurrent/qthreadpool.h
index cc1e059..9895c41 100644
--- a/src/corelib/concurrent/qthreadpool.h
+++ b/src/corelib/concurrent/qthreadpool.h
@@ -84,7 +84,7 @@ public:
void reserveThread();
void releaseThread();
- void waitForDone();
+ void waitForDone(int msecs = -1);
};
QT_END_NAMESPACE
diff --git a/src/corelib/concurrent/qthreadpool_p.h b/src/corelib/concurrent/qthreadpool_p.h
index 8a2cf98..1a0e4ab 100644
--- a/src/corelib/concurrent/qthreadpool_p.h
+++ b/src/corelib/concurrent/qthreadpool_p.h
@@ -82,7 +82,7 @@ public:
void startThread(QRunnable *runnable = 0);
void reset();
- void waitForDone();
+ void waitForDone(int msecs = -1);
bool startFrontRunnable();
void stealRunnable(QRunnable *);