diff options
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qthread.cpp | 25 | ||||
-rw-r--r-- | src/corelib/thread/qthread_p.h | 10 |
2 files changed, 34 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) { diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index 6825718..54ffd80 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -112,6 +112,15 @@ public: }; #ifndef QT_NO_THREAD + +class QThreadPrivateInternalObject : public QObject +{ + Q_OBJECT + +public slots: + void exit(int); +}; + class QThreadPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QThread) @@ -156,6 +165,7 @@ public: bool terminationEnabled, terminatePending; # endif QThreadData *data; + QThreadPrivateInternalObject *object; static void createEventDispatcher(QThreadData *data); }; |