diff --git a/src/core/kernel/qcoreapplication.cpp b/src/core/kernel/qcoreapplication.cpp index 4fc8694f0..9ca952efa 100644 --- a/src/core/kernel/qcoreapplication.cpp +++ b/src/core/kernel/qcoreapplication.cpp @@ -49,6 +49,19 @@ QT_BEGIN_NAMESPACE +class QMutexUnlocker +{ +public: + inline explicit QMutexUnlocker(QMutex *m) : mtx(m) { } + inline ~QMutexUnlocker() { unlock(); } + inline void unlock() { if (mtx) mtx->unlock(); mtx = 0; } + +private: + Q_DISABLE_COPY(QMutexUnlocker) + + QMutex *mtx; +}; + bool QCoreApplicationPrivate::checkInstance(const char *function) { if (Q_UNLIKELY(!QCoreApplication::self)) { @@ -818,7 +831,7 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) } // lock the post event mutex - QMutexLocker locker(&data->postEventList.mutex); + data->postEventList.mutex.lock(); // if object has moved to another thread, follow it while (data != *pdata) { @@ -834,6 +847,8 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) data->postEventList.mutex.lock(); } + QMutexUnlocker locker(&data->postEventList.mutex); + // if this is one of the compressible events, do compression if (receiver->d_func()->postedEvents && self && self->compressEvent(event, receiver, &data->postEventList)) {