From e0e9d4ea2cec37243d964a5309be49101d112233 Mon Sep 17 00:00:00 2001 From: Tijl Coosemans Date: Fri, 26 Nov 2010 10:11:10 +0100 Subject: QKqueueFileSystemWatcherEngine: Unlock mutex between two events. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the worker thread unlock the mutex between processing two events. Otherwise it's possible for the worker thread to block the application thread when many events occur. Also, there's no need to lock the mutex when processing a pipe event. Generally the worker thread should hamper the application thread as little as possible, so only lock the mutex where needed. Merge-request: 2425 Reviewed-by: João Abecasis --- src/corelib/io/qfilesystemwatcher_kqueue.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp index 8fba091..637a961 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -235,8 +235,6 @@ void QKqueueFileSystemWatcherEngine::stop() void QKqueueFileSystemWatcherEngine::run() { - static const struct timespec ZeroTimeout = { 0, 0 }; - forever { int r; struct kevent kev; @@ -245,10 +243,7 @@ void QKqueueFileSystemWatcherEngine::run() if (r < 0) { perror("QKqueueFileSystemWatcherEngine: error during kevent wait"); return; - } - - QMutexLocker locker(&mutex); - do { + } else { int fd = kev.ident; DEBUG() << "QKqueueFileSystemWatcherEngine: processing kevent" << kev.ident << kev.filter; @@ -280,6 +275,8 @@ void QKqueueFileSystemWatcherEngine::run() break; } } else { + QMutexLocker locker(&mutex); + int id = fd; QString path = idToPath.value(id); if (path.isEmpty()) { @@ -288,12 +285,12 @@ void QKqueueFileSystemWatcherEngine::run() path = idToPath.value(id); if (path.isEmpty()) { DEBUG() << "QKqueueFileSystemWatcherEngine: received a kevent for a file we're not watching"; - goto process_next_event; + continue; } } if (kev.filter != EVFILT_VNODE) { DEBUG() << "QKqueueFileSystemWatcherEngine: received a kevent with the wrong filter"; - goto process_next_event; + continue; } if ((kev.fflags & (NOTE_DELETE | NOTE_REVOKE | NOTE_RENAME)) != 0) { @@ -316,11 +313,7 @@ void QKqueueFileSystemWatcherEngine::run() emit fileChanged(path, false); } } - - // are there any more? -process_next_event: - r = kevent(kqfd, 0, 0, &kev, 1, &ZeroTimeout); - } while (r > 0); + } } } -- cgit v0.12