summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2010-04-14 12:55:23 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2010-04-14 12:57:29 (GMT)
commit5c42726aac64dd270dc5f7dd87ad925db2ee46cf (patch)
tree4131389aee59af63c0a5a4ef5bc3ca6178b8f277 /src/corelib
parente5d1bb8e20cfa322807198359efc05c18938b2f3 (diff)
downloadQt-5c42726aac64dd270dc5f7dd87ad925db2ee46cf.zip
Qt-5c42726aac64dd270dc5f7dd87ad925db2ee46cf.tar.gz
Qt-5c42726aac64dd270dc5f7dd87ad925db2ee46cf.tar.bz2
Fix a race where QThread::exit() is "lost" when called after start()
This reverts commit 9aa4538b219ed759a47e8d1f93c2797bf07b5e2f and fixes the bug in a different way. If the QThreadData::quitNow flag is set when entering QThread::exec(), allow QEventLoop::exec() to bail out and reset quitNow after QEventLoop::exec() has returned (not before). Task-number: QTBUG-1184 Reviewed-by: olivier
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/thread/qthread.cpp31
-rw-r--r--src/corelib/thread/qthread_p.h9
-rw-r--r--src/corelib/thread/qthread_unix.cpp2
-rw-r--r--src/corelib/thread/qthread_win.cpp2
4 files changed, 6 insertions, 38 deletions
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index c35eb28..cdcb65c 100644
--- a/src/corelib/thread/qthread.cpp
+++ b/src/corelib/thread/qthread.cpp
@@ -174,7 +174,7 @@ void QAdoptedThread::run()
QThreadPrivate::QThreadPrivate(QThreadData *d)
: QObjectPrivate(), running(false), finished(false), terminated(false),
- stackSize(0), priority(QThread::InheritPriority), data(d), object(0)
+ stackSize(0), priority(QThread::InheritPriority), data(d)
{
#if defined (Q_OS_UNIX)
thread_id = 0;
@@ -377,9 +377,6 @@ QThread::QThread(QObject *parent)
Q_D(QThread);
// fprintf(stderr, "QThreadData %p created for thread %p\n", d->data, this);
d->data->thread = this;
-
- d->object = new QThreadPrivateInternalObject;
- d->object->moveToThread(this);
}
/*! \internal
@@ -390,8 +387,6 @@ QThread::QThread(QThreadPrivate &dd, QObject *parent)
Q_D(QThread);
// fprintf(stderr, "QThreadData %p taken from private data for thread %p\n", d->data, this);
d->data->thread = this;
-
- // do not create the internal object for adopted threads
}
/*!
@@ -413,9 +408,6 @@ QThread::~QThread()
d->data->thread = 0;
}
-
- delete d->object;
- d->object = 0;
}
/*!
@@ -488,11 +480,11 @@ uint QThread::stackSize() const
int QThread::exec()
{
Q_D(QThread);
- QMutexLocker locker(&d->mutex);
- d->data->quitNow = false;
QEventLoop eventLoop;
- locker.unlock();
int returnCode = eventLoop.exec();
+
+ QMutexLocker locker(&d->mutex);
+ d->data->quitNow = false;
return returnCode;
}
@@ -518,21 +510,6 @@ int QThread::exec()
void QThread::exit(int returnCode)
{
Q_D(QThread);
- if (d->object) {
- QMetaObject::invokeMethod(d->object, "exit", Q_ARG(int, returnCode));
- } else {
- QMutexLocker locker(&d->mutex);
- d->data->quitNow = true;
- for (int i = 0; i < d->data->eventLoops.size(); ++i) {
- QEventLoop *eventLoop = d->data->eventLoops.at(i);
- eventLoop->exit(returnCode);
- }
- }
-}
-
-void QThreadPrivateInternalObject::exit(int returnCode)
-{
- QThreadPrivate *d = static_cast<QThreadPrivate *>(QObjectPrivate::get(thread()));
QMutexLocker locker(&d->mutex);
d->data->quitNow = true;
for (int i = 0; i < d->data->eventLoops.size(); ++i) {
diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h
index 54ffd80..44eb8f8 100644
--- a/src/corelib/thread/qthread_p.h
+++ b/src/corelib/thread/qthread_p.h
@@ -113,14 +113,6 @@ public:
#ifndef QT_NO_THREAD
-class QThreadPrivateInternalObject : public QObject
-{
- Q_OBJECT
-
-public slots:
- void exit(int);
-};
-
class QThreadPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QThread)
@@ -165,7 +157,6 @@ public:
bool terminationEnabled, terminatePending;
# endif
QThreadData *data;
- QThreadPrivateInternalObject *object;
static void createEventDispatcher(QThreadData *data);
};
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index 6b34b5f..bd31d9c 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -253,7 +253,6 @@ void *QThreadPrivate::start(void *arg)
pthread_setspecific(current_thread_data_key, data);
data->ref();
- data->quitNow = false;
// ### TODO: allow the user to create a custom event dispatcher
createEventDispatcher(data);
@@ -495,6 +494,7 @@ void QThread::start(Priority priority)
d->running = true;
d->finished = false;
d->terminated = false;
+ d->data->quitNow = false;
pthread_attr_t attr;
pthread_attr_init(&attr);
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp
index 37d5b87..9826dcb 100644
--- a/src/corelib/thread/qthread_win.cpp
+++ b/src/corelib/thread/qthread_win.cpp
@@ -298,7 +298,6 @@ unsigned int __stdcall QThreadPrivate::start(void *arg)
QThread::setTerminationEnabled(false);
- data->quitNow = false;
// ### TODO: allow the user to create a custom event dispatcher
createEventDispatcher(data);
@@ -405,6 +404,7 @@ void QThread::start(Priority priority)
d->running = true;
d->finished = false;
d->terminated = false;
+ d->data->quitNow = false;
/*
NOTE: we create the thread in the suspended state, set the