summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qthread.cpp
diff options
context:
space:
mode:
authorMartin Smith <msmith@trolltech.com>2010-04-13 08:20:16 (GMT)
committerMartin Smith <msmith@trolltech.com>2010-04-13 08:20:16 (GMT)
commitadd41080b9a4e2319007063bd73447f336933e9e (patch)
tree2b5bcbf18d4a0b3dc96043a430830c8212e85749 /src/corelib/thread/qthread.cpp
parent1055099e331af3b10d0b81b1a965e7d3db5f272d (diff)
parentfbacd0fb2eb41470b090a3cbca7535f78689a382 (diff)
downloadQt-add41080b9a4e2319007063bd73447f336933e9e.zip
Qt-add41080b9a4e2319007063bd73447f336933e9e.tar.gz
Qt-add41080b9a4e2319007063bd73447f336933e9e.tar.bz2
Merge branch '4.7' of git@scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7
Diffstat (limited to 'src/corelib/thread/qthread.cpp')
-rw-r--r--src/corelib/thread/qthread.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index cb84538..c35eb28 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)
+ stackSize(0), priority(QThread::InheritPriority), data(d), object(0)
{
#if defined (Q_OS_UNIX)
thread_id = 0;
@@ -377,6 +377,9 @@ 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
@@ -387,6 +390,8 @@ 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
}
/*!
@@ -408,6 +413,9 @@ QThread::~QThread()
d->data->thread = 0;
}
+
+ delete d->object;
+ d->object = 0;
}
/*!
@@ -510,6 +518,21 @@ 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) {