diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-04-23 09:29:12 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-04-23 10:10:59 (GMT) |
commit | 662f33a5b39f31579a2557a4d81469cfe30815c7 (patch) | |
tree | c56c2bcc9f4b1d28f30c76d44782bc4af4185c51 | |
parent | d11cf4b8795a0f39e76432aa805f098388579d2d (diff) | |
download | Qt-662f33a5b39f31579a2557a4d81469cfe30815c7.zip Qt-662f33a5b39f31579a2557a4d81469cfe30815c7.tar.gz Qt-662f33a5b39f31579a2557a4d81469cfe30815c7.tar.bz2 |
Allow QThread to start a QTimer and QEventLoop before QCoreApplication is constructed
Fix a regression from 4.3 to 4.4 that prevented QThread from starting
timers and event loops before QCoreApplication was instantiated. Even
though this is documented not to work, it seems that people have been
relying on it.
This reverts commit e52e5acdfa198cd079bbfe3a9302debf46c7cadd which
attempted to work around not calling g_thread_init() multiple
times. The proper fix is to serialize the g_thread_supported() checks
in the Glib event dispatcher.
Task-number: 248191
Reviewed-by: denis
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_glib.cpp | 3 | ||||
-rw-r--r-- | src/corelib/kernel/qeventloop.cpp | 5 | ||||
-rw-r--r-- | src/corelib/thread/qthread_unix.cpp | 3 | ||||
-rw-r--r-- | src/corelib/thread/qthread_win.cpp | 3 |
4 files changed, 8 insertions, 6 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp index 3fd768a..3c5b277 100644 --- a/src/corelib/kernel/qeventdispatcher_glib.cpp +++ b/src/corelib/kernel/qeventdispatcher_glib.cpp @@ -42,6 +42,7 @@ #include "qeventdispatcher_glib_p.h" #include "qeventdispatcher_unix_p.h" +#include <private/qmutexpool_p.h> #include <private/qthread_p.h> #include "qcoreapplication.h" @@ -224,6 +225,8 @@ QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context) : mainContext(context) { if (qgetenv("QT_NO_THREADED_GLIB").isEmpty()) { + static int dummyValue = 0; // only used for its address + QMutexLocker locker(QMutexPool::instance()->get(&dummyValue)); if (!g_thread_supported()) g_thread_init(NULL); } diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index 92bdf73..600f787 100644 --- a/src/corelib/kernel/qeventloop.cpp +++ b/src/corelib/kernel/qeventloop.cpp @@ -188,8 +188,9 @@ int QEventLoop::exec(ProcessEventsFlags flags) d->threadData->eventLoops.push(this); // remove posted quit events when entering a new event loop - if (qApp->thread() == thread()) - QCoreApplication::removePostedEvents(qApp, QEvent::Quit); + QCoreApplication *app = QCoreApplication::instance(); + if (app && app->thread() == thread()) + QCoreApplication::removePostedEvents(app, QEvent::Quit); #if defined(QT_NO_EXCEPTIONS) while (!d->exit) diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index f602821..8f1c698 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -180,8 +180,7 @@ void *QThreadPrivate::start(void *arg) data->quitNow = false; // ### TODO: allow the user to create a custom event dispatcher - if (QCoreApplication::instance()) - createEventDispatcher(data); + createEventDispatcher(data); emit thr->started(); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 27193c6..7094e3d 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -292,8 +292,7 @@ unsigned int __stdcall QThreadPrivate::start(void *arg) data->quitNow = false; // ### TODO: allow the user to create a custom event dispatcher - if (QCoreApplication::instance()) - createEventDispatcher(data); + createEventDispatcher(data); #if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) && !defined(Q_OS_WINCE) // sets the name of the current thread. |