diff options
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_unix.cpp | 22 | ||||
-rw-r--r-- | tests/auto/qtimer/tst_qtimer.cpp | 64 |
2 files changed, 74 insertions, 12 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index 9dadd82..f50994c 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -549,18 +549,22 @@ int QTimerInfoList::activateTimers() if (qt_disable_lowpriority_timers || isEmpty()) return 0; // nothing to do - bool firstTime = true; - timeval currentTime; - int n_act = 0, maxCount = count(); + int n_act = 0, maxCount = 0; firstTimerInfo = 0; - while (maxCount--) { - currentTime = updateCurrentTime(); - if (firstTime) { - repairTimersIfNeeded(); - firstTime = false; - } + timeval currentTime = updateCurrentTime(); + repairTimersIfNeeded(); + + // Find out how many timer have expired + for (QTimerInfoList::const_iterator it = constBegin(); it != constEnd(); ++it) { + if (currentTime < (*it)->timeout) + break; + maxCount++; + } + + //fire the timers. + while (maxCount--) { if (isEmpty()) break; diff --git a/tests/auto/qtimer/tst_qtimer.cpp b/tests/auto/qtimer/tst_qtimer.cpp index b651187..4ed42cf 100644 --- a/tests/auto/qtimer/tst_qtimer.cpp +++ b/tests/auto/qtimer/tst_qtimer.cpp @@ -87,6 +87,8 @@ private slots: void cancelLongTimer(); void singleShotStaticFunctionZeroTimeout(); void recurseOnTimeoutAndStopTimer(); + + void QTBUG13633_dontBlockEvents(); }; class TimerHelper : public QObject @@ -272,9 +274,6 @@ void tst_QTimer::livelock() #if defined(Q_OS_MAC) QEXPECT_FAIL("zero timer", "Posted events source are handled AFTER timers", Continue); QEXPECT_FAIL("non-zero timer", "Posted events source are handled AFTER timers", Continue); -#elif defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) - QEXPECT_FAIL("zero timer", "", Continue); - QEXPECT_FAIL("non-zero timer", "", Continue); #elif defined(Q_OS_WIN) && !defined(Q_OS_WINCE) if (QSysInfo::WindowsVersion < QSysInfo::WV_XP) QEXPECT_FAIL("non-zero timer", "Multimedia timers are not available on Windows 2000", Continue); @@ -668,5 +667,64 @@ void tst_QTimer::recurseOnTimeoutAndStopTimer() QVERIFY(!t.two->isActive()); } + + +class DontBlockEvents : public QObject +{ + Q_OBJECT +public: + DontBlockEvents(); + void timerEvent(QTimerEvent*); + + int count; + int total; + QBasicTimer m_timer; + +public slots: + void paintEvent(); + +}; + +DontBlockEvents::DontBlockEvents() +{ + count = 0; + total = 0; + + //QTBUG-13633 need few unrelated timer running to reproduce the bug. + (new QTimer(this))->start(2000); + (new QTimer(this))->start(2500); + (new QTimer(this))->start(3000); + (new QTimer(this))->start(5000); + (new QTimer(this))->start(1000); + (new QTimer(this))->start(2000); + + m_timer.start(1, this); +} + +void DontBlockEvents::timerEvent(QTimerEvent* event) +{ + if (event->timerId() == m_timer.timerId()) { + m_timer.start(0, this); + QMetaObject::invokeMethod(this, "paintEvent", Qt::QueuedConnection); + count++; + QCOMPARE(count, 1); + total++; + } +} + +void DontBlockEvents::paintEvent() +{ + count--; + QCOMPARE(count, 0); +} + + +void tst_QTimer::QTBUG13633_dontBlockEvents() +{ + DontBlockEvents t; + QTest::qWait(60); + QVERIFY(t.total > 2); +} + QTEST_MAIN(tst_QTimer) #include "tst_qtimer.moc" |