summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qthread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/thread/qthread.cpp')
-rw-r--r--src/corelib/thread/qthread.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index cdcb65c..2c63dfc 100644
--- a/src/corelib/thread/qthread.cpp
+++ b/src/corelib/thread/qthread.cpp
@@ -173,7 +173,7 @@ void QAdoptedThread::run()
*/
QThreadPrivate::QThreadPrivate(QThreadData *d)
- : QObjectPrivate(), running(false), finished(false), terminated(false),
+ : QObjectPrivate(), running(false), finished(false), terminated(false), exited(false), returnCode(-1),
stackSize(0), priority(QThread::InheritPriority), data(d)
{
#if defined (Q_OS_UNIX)
@@ -480,11 +480,18 @@ uint QThread::stackSize() const
int QThread::exec()
{
Q_D(QThread);
+ QMutexLocker locker(&d->mutex);
+ d->data->quitNow = false;
+ if (d->exited)
+ return d->returnCode;
+ locker.unlock();
+
QEventLoop eventLoop;
int returnCode = eventLoop.exec();
- QMutexLocker locker(&d->mutex);
- d->data->quitNow = false;
+ locker.relock();
+ d->exited = false;
+ d->returnCode = -1;
return returnCode;
}
@@ -511,6 +518,8 @@ void QThread::exit(int returnCode)
{
Q_D(QThread);
QMutexLocker locker(&d->mutex);
+ d->exited = true;
+ d->returnCode = returnCode;
d->data->quitNow = true;
for (int i = 0; i < d->data->eventLoops.size(); ++i) {
QEventLoop *eventLoop = d->data->eventLoops.at(i);