summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2013-03-15 19:47:46 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-22 12:12:36 +0100
commitbf3a5ccef13d568662f027be62280aba1f73bada (patch)
treeffb684ec1c5be91bfe7fefc1be589147a4502801 /src/corelib
parent49d7e71f77f899c05e4b5187e8834dfcbddf4505 (diff)
QThreadDataPrivate: fix data race on canWait boolean.
postEvent() accesses it with the postEventList mutex locked, but processEvent() was checking it without any mutex locked. Change-Id: I31bbb50f7a1c337067b8e3de16ee7cd11400b517 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/kernel/qeventdispatcher_glib.cpp5
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix.cpp2
-rw-r--r--src/corelib/thread/qthread_p.h6
3 files changed, 10 insertions, 3 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp
index 17830868da..e87e830c39 100644
--- a/src/corelib/kernel/qeventdispatcher_glib.cpp
+++ b/src/corelib/kernel/qeventdispatcher_glib.cpp
@@ -259,10 +259,11 @@ static gboolean postEventSourcePrepare(GSource *s, gint *timeout)
gint dummy;
if (!timeout)
timeout = &dummy;
- *timeout = data->canWait ? -1 : 0;
+ const bool canWait = data->canWaitLocked();
+ *timeout = canWait ? -1 : 0;
GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s);
- return (!data->canWait
+ return (!canWait
|| (source->serialNumber.load() != source->lastSerialNumber));
}
diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp
index ae220363ba..6ef8c5621e 100644
--- a/src/corelib/kernel/qeventdispatcher_unix.cpp
+++ b/src/corelib/kernel/qeventdispatcher_unix.cpp
@@ -589,7 +589,7 @@ bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags)
QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData);
int nevents = 0;
- const bool canWait = (d->threadData->canWait
+ const bool canWait = (d->threadData->canWaitLocked()
&& !d->interrupt.load()
&& (flags & QEventLoop::WaitForMoreEvents));
diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h
index 2cf988260f..8e9eb1035a 100644
--- a/src/corelib/thread/qthread_p.h
+++ b/src/corelib/thread/qthread_p.h
@@ -231,6 +231,12 @@ public:
void ref();
void deref();
+ bool canWaitLocked()
+ {
+ QMutexLocker locker(&postEventList.mutex);
+ return canWait;
+ }
+
QThread *thread;
Qt::HANDLE threadId;
bool quitNow;