Don't release timer ids in event dispatcher code
authorBradley T. Hughes <bradley.hughes@nokia.com>
Tue, 20 Dec 2011 10:38:35 +0000 (11:38 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 4 Jan 2012 13:31:57 +0000 (14:31 +0100)
commitf821d6352e384a737c82a0db903104ec4f8611bd
tree6efe50e3f754c8e51dec5085ffb4d68722791eac
parentbd525a64d5fb55d1c67fdecdad9ed920a3d83666
Don't release timer ids in event dispatcher code

3rdparty event dispatchers are impossible to write without using the
internal API QAbstractEventDispatcherPrivate::releaseTimerId(). Fix
this by having each QObject keep track of its own timer ids, and
release them when they are no longer used. As a side effect, this
makes the QObjectData::pendTimer bit unnecessary.

This also removes the QObjectData::inThreadChangeEvent hack that the
event dispatchers used to avoid releasing timer ids when moving timers
to a new thread.

QBasicTimer becomes even more low-level. It cannot use
QObject::startTimer() anymore, since we do not have a way to call
QObject::killTimer() from QBasicTimer::stop(). QBasicTimer uses the
QAbstractEventDispatcher interface directly, and releases the timer id
explicitly as well when stopping the timer.

This change also fixes some rare timer id "leaks" when destroying or
stopping timers after a thread has exited and destroyed its event
dispatcher (the timer ids would never be released when no dispatcher
exists).

Globally destructed QObjects that have running timers may try to release
their timer ids after the timer id freelist has been destroyed. This
commit accomodates such objects by avoiding the null dereference in
QAbstractEventDispatcherPrivate::releaseTimerId().

Change-Id: I2d7cd8221fae441f3cf02b6c0b4bc16063834d00
Reviewed-by: David Faure <faure@kde.org>
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
src/corelib/kernel/qabstracteventdispatcher.cpp
src/corelib/kernel/qbasictimer.cpp
src/corelib/kernel/qeventdispatcher_win.cpp
src/corelib/kernel/qeventdispatcher_win_p.h
src/corelib/kernel/qobject.cpp
src/corelib/kernel/qobject.h
src/corelib/kernel/qobject_p.h
src/corelib/kernel/qtimerinfo_unix.cpp
src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm