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>
bb10
David Faure 2013-03-15 19:47:46 +01:00 committed by The Qt Project
parent 49d7e71f77
commit bf3a5ccef1
3 changed files with 10 additions and 3 deletions

View File

@ -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));
}

View File

@ -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));

View File

@ -231,6 +231,12 @@ public:
void ref();
void deref();
bool canWaitLocked()
{
QMutexLocker locker(&postEventList.mutex);
return canWait;
}
QThread *thread;
Qt::HANDLE threadId;
bool quitNow;