Avoid races when destroying QFileSystemWatcher

On Mac OS X, socket notifiers need to be disabled/destroyed before
closing their associated file descriptor, otherwise we cause races
inside the CFSocket system. The documentation for CFSocketInvalidate()
says that we close the file descriptor after calling this function when
the kCFSocketCloseOnInvalidate flag is explicitly cleared
(QCocoaEventDispatcher clears this flag).

Do the same on the Linux inotify watcher as well, for symmetry.

Change-Id: I5592cc4bb5be4b752e48d895a685d3c92826acc7
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
This commit is contained in:
Bradley T. Hughes 2012-01-11 12:42:50 +01:00 committed by Qt by Nokia
parent dd22fe636b
commit d6e0306a90
2 changed files with 2 additions and 0 deletions

View File

@ -234,6 +234,7 @@ QInotifyFileSystemWatcherEngine::QInotifyFileSystemWatcherEngine(int fd)
QInotifyFileSystemWatcherEngine::~QInotifyFileSystemWatcherEngine()
{
notifier.setEnabled(false);
foreach (int id, pathToID)
inotify_rm_watch(inotifyFd, id < 0 ? -id : id);

View File

@ -86,6 +86,7 @@ QKqueueFileSystemWatcherEngine::QKqueueFileSystemWatcherEngine(int kqfd)
QKqueueFileSystemWatcherEngine::~QKqueueFileSystemWatcherEngine()
{
notifier.setEnabled(false);
close(kqfd);
foreach (int id, pathToID)