diff options
author | David Faure <david.faure@kdab.com> | 2013-03-18 15:19:44 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-22 16:44:51 +0100 |
commit | f4609b202208fe592d24c7ae3b4a48ee83045497 (patch) | |
tree | c9827efe74688595664c379085ba2a6267e49c13 /src/corelib/kernel/qcoreapplication.cpp | |
parent | 85b25fc22176b574865813fa53f7eb2fcbdc89bf (diff) |
QThread: fix race when setting the eventDispatcher
Use QAtomicPointer to make this thread-safe.
Change-Id: If71f204699fcefabdb59bd26342d777d1cc9e2a7
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/kernel/qcoreapplication.cpp')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index cce8c30d81..61a8b6a18c 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -689,7 +689,7 @@ void QCoreApplication::init() #ifndef QT_NO_QOBJECT // use the event dispatcher created by the app programmer (if any) if (!QCoreApplicationPrivate::eventDispatcher) - QCoreApplicationPrivate::eventDispatcher = d->threadData->eventDispatcher; + QCoreApplicationPrivate::eventDispatcher = d->threadData->eventDispatcher.load(); // otherwise we create one if (!QCoreApplicationPrivate::eventDispatcher) d->createEventDispatcher(); @@ -1031,9 +1031,9 @@ bool QCoreApplication::closingDown() void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags) { QThreadData *data = QThreadData::current(); - if (!data->eventDispatcher) + if (!data->hasEventDispatcher()) return; - data->eventDispatcher->processEvents(flags); + data->eventDispatcher.load()->processEvents(flags); } /*! @@ -1055,11 +1055,11 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags) void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime) { QThreadData *data = QThreadData::current(); - if (!data->eventDispatcher) + if (!data->hasEventDispatcher()) return; QElapsedTimer start; start.start(); - while (data->eventDispatcher->processEvents(flags & ~QEventLoop::WaitForMoreEvents)) { + while (data->eventDispatcher.load()->processEvents(flags & ~QEventLoop::WaitForMoreEvents)) { if (start.elapsed() > maxtime) break; } @@ -1258,8 +1258,9 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) data->canWait = false; locker.unlock(); - if (data->eventDispatcher) - data->eventDispatcher->wakeUp(); + QAbstractEventDispatcher* dispatcher = data->eventDispatcher.loadAcquire(); + if (dispatcher) + dispatcher->wakeUp(); } /*! @@ -1379,8 +1380,8 @@ void QCoreApplicationPrivate::sendPostedEvents(QObject *receiver, int event_type } --data->postEventList.recursion; - if (!data->postEventList.recursion && !data->canWait && data->eventDispatcher) - data->eventDispatcher->wakeUp(); + if (!data->postEventList.recursion && !data->canWait && data->hasEventDispatcher()) + data->eventDispatcher.load()->wakeUp(); // clear the global list, i.e. remove everything that was // delivered. |