summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-04-08 09:07:33 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-04-08 09:28:06 (GMT)
commit74f092408d1a870e2c1e2a49182c8e09f952055d (patch)
treebc3fd9f069ecd84a842650ba028df6d46f850238
parentc131208e59f5b2dd517b00c4539458760b8fd8aa (diff)
downloadQt-74f092408d1a870e2c1e2a49182c8e09f952055d.zip
Qt-74f092408d1a870e2c1e2a49182c8e09f952055d.tar.gz
Qt-74f092408d1a870e2c1e2a49182c8e09f952055d.tar.bz2
Javascript: When there is javascript running then it will spin the CPU at 100%
Zero timers on Windows would continue to fire even after being stopped as long as a new timer was started that reused the pointer address of the zero timer. Fix this by only re-firing zero timers if the zero timer hadn't been stopped (we can check this by looking at the inTimerEvent flag, which is set to false by registerTimer()). Task-number: 247401 Reviewed-by: Denis Dzyubenko Reviewed-by: Prasanth Ullattil
-rw-r--r--dist/changes-4.5.14
-rw-r--r--src/corelib/kernel/qeventdispatcher_win.cpp15
-rw-r--r--tests/auto/qtimer/tst_qtimer.cpp65
3 files changed, 81 insertions, 3 deletions
diff --git a/dist/changes-4.5.1 b/dist/changes-4.5.1
index de4eef7..eb8ec5f 100644
--- a/dist/changes-4.5.1
+++ b/dist/changes-4.5.1
@@ -68,6 +68,10 @@ Qt for Linux/X11
Qt for Windows
--------------
+- QCoreApplication
+ * [247401] Fixed a bug that would cause a restarted timer to fire
+ too early, causing Javascript in QtWebKit to consume 100% CPU on
+ Windows.
Qt for Mac OS X
---------------
diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp
index 880e95c..c4061f4 100644
--- a/src/corelib/kernel/qeventdispatcher_win.cpp
+++ b/src/corelib/kernel/qeventdispatcher_win.cpp
@@ -1059,11 +1059,20 @@ bool QEventDispatcherWin32::event(QEvent *e)
QZeroTimerEvent *zte = static_cast<QZeroTimerEvent*>(e);
WinTimerInfo *t = d->timerDict.value(zte->timerId());
if (t) {
+ t->inTimerEvent = true;
+
QTimerEvent te(zte->timerId());
QCoreApplication::sendEvent(t->obj, &te);
- WinTimerInfo *tn = d->timerDict.value(zte->timerId());
- if (tn && t == tn)
- QCoreApplication::postEvent(this, new QZeroTimerEvent(zte->timerId()));
+
+ t = d->timerDict.value(zte->timerId());
+ if (t) {
+ if (t->interval == 0 && t->inTimerEvent) {
+ // post the next zero timer event as long as the timer was not restarted
+ QCoreApplication::postEvent(this, new QZeroTimerEvent(zte->timerId()));
+ }
+
+ t->inTimerEvent = false;
+ }
}
return true;
} else if (e->type() == QEvent::Timer) {
diff --git a/tests/auto/qtimer/tst_qtimer.cpp b/tests/auto/qtimer/tst_qtimer.cpp
index 527628c..bffb4f2 100644
--- a/tests/auto/qtimer/tst_qtimer.cpp
+++ b/tests/auto/qtimer/tst_qtimer.cpp
@@ -83,6 +83,7 @@ private slots:
void recurringTimer();
void deleteLaterOnQTimer(); // long name, don't want to shadow QObject::deleteLater()
void moveToThread();
+ void restartedTimerFiresTooSoon();
};
class TimerHelper : public QObject
@@ -416,5 +417,69 @@ void tst_QTimer::moveToThread()
QVERIFY((ti3.timerId() & 0xffffff) != (ti1.timerId() & 0xffffff));
}
+class RestartedTimerFiresTooSoonObject : public QObject
+{
+ Q_OBJECT
+
+public:
+ QBasicTimer m_timer;
+
+ int m_interval;
+ QTime m_startedTime;
+ QEventLoop eventLoop;
+
+ inline RestartedTimerFiresTooSoonObject()
+ : QObject(), m_interval(0)
+ { }
+
+ void timerFired()
+ {
+ static int interval = 1000;
+
+ m_interval = interval;
+ m_startedTime.start();
+ m_timer.start(interval, this);
+
+ // alternate between single-shot and 1 sec
+ interval = interval ? 0 : 1000;
+ }
+
+ void timerEvent(QTimerEvent* ev)
+ {
+ if (ev->timerId() != m_timer.timerId())
+ return;
+
+ m_timer.stop();
+
+ QTime now = QTime::currentTime();
+ int elapsed = m_startedTime.elapsed();
+
+ if (elapsed < m_interval / 2) {
+ // severely too early!
+ m_timer.stop();
+ eventLoop.exit(-1);
+ return;
+ }
+
+ timerFired();
+
+ // don't do this forever
+ static int count = 0;
+ if (count++ > 20) {
+ m_timer.stop();
+ eventLoop.quit();
+ return;
+ }
+ }
+};
+
+void tst_QTimer::restartedTimerFiresTooSoon()
+{
+ RestartedTimerFiresTooSoonObject object;
+ object.timerFired();
+ QVERIFY(object.eventLoop.exec() == 0);
+}
+
QTEST_MAIN(tst_QTimer)
#include "tst_qtimer.moc"
+\