From 84c3b3e32612149d128d5288aebdf27badb8d43c Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 12 Nov 2010 10:49:13 +0100 Subject: QFileSystemWatcher: Do not require QApplication in the destructor. QThread::quit() is threadsafe, and can safely (and should) be called from the parent thread. Using invokeMethod requires an instance of QCoreApplication. There is no reason we should depend on that. Task-number: QTBUG-15255 Task-number: QT-3305 Reviewed-by: Denis Reviewed-by: Brad --- src/corelib/io/qfilesystemwatcher.cpp | 7 +------ src/corelib/io/qfilesystemwatcher_inotify.cpp | 2 +- src/corelib/io/qfilesystemwatcher_symbian.cpp | 2 +- .../qfilesystemwatcher/tst_qfilesystemwatcher.cpp | 20 ++++++++++++++++++++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp index 34eff75..9739067 100644 --- a/src/corelib/io/qfilesystemwatcher.cpp +++ b/src/corelib/io/qfilesystemwatcher.cpp @@ -198,7 +198,7 @@ QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &path void QPollingFileSystemWatcherEngine::stop() { - QMetaObject::invokeMethod(this, "quit"); + quit(); } void QPollingFileSystemWatcherEngine::timeout() @@ -432,11 +432,6 @@ QFileSystemWatcher::QFileSystemWatcher(const QStringList &paths, QObject *parent /*! Destroys the file system watcher. - - \note To avoid deadlocks on shutdown, all instances of QFileSystemWatcher - need to be destroyed before QCoreApplication. Note that passing - QCoreApplication::instance() as the parent object when creating - QFileSystemWatcher is not sufficient. */ QFileSystemWatcher::~QFileSystemWatcher() { diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index 8c81de8..2eec117 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -340,7 +340,7 @@ QStringList QInotifyFileSystemWatcherEngine::removePaths(const QStringList &path void QInotifyFileSystemWatcherEngine::stop() { - QMetaObject::invokeMethod(this, "quit"); + quit(); } void QInotifyFileSystemWatcherEngine::readFromInotify() diff --git a/src/corelib/io/qfilesystemwatcher_symbian.cpp b/src/corelib/io/qfilesystemwatcher_symbian.cpp index 0d8f22e..95c65c0 100644 --- a/src/corelib/io/qfilesystemwatcher_symbian.cpp +++ b/src/corelib/io/qfilesystemwatcher_symbian.cpp @@ -215,7 +215,7 @@ void QSymbianFileSystemWatcherEngine::emitPathChanged(QNotifyChangeEvent *e) void QSymbianFileSystemWatcherEngine::stop() { - QMetaObject::invokeMethod(this, "quit"); + quit(); wait(); } diff --git a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 8e0c9fe..9d46a8d 100644 --- a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -82,6 +82,8 @@ private slots: void removeFileAndUnWatch(); void cleanup(); + + void QTBUG15255_deadlock(); private: QStringList do_force_engines; bool do_force_native; @@ -550,5 +552,23 @@ void tst_QFileSystemWatcher::removeFileAndUnWatch() watcher.addPath(filename); } +class SomeSingleton : public QObject +{ +public: + SomeSingleton() : mFsWatcher(new QFileSystemWatcher(this)) { mFsWatcher->addPath(QLatin1String("/usr/lib"));} + void bla() const {} + QFileSystemWatcher* mFsWatcher; +}; + +Q_GLOBAL_STATIC(SomeSingleton, someSingleton) + +void tst_QFileSystemWatcher::QTBUG15255_deadlock() +{ + someSingleton()->bla(); + //the test must still finish + QTest::qWait(30); +} + + QTEST_MAIN(tst_QFileSystemWatcher) #include "tst_qfilesystemwatcher.moc" -- cgit v0.12