summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTijl Coosemans <tijl@coosemans.org>2010-11-26 09:11:10 (GMT)
committerJoão Abecasis <joao.abecasis@nokia.com>2010-11-26 09:11:10 (GMT)
commitc6d4a2ca73ac57d47adee35d0d11c98c8b5130ee (patch)
tree1085105d8262b70e1c7bb9e0164e1885d88daf7f
parentd977d5f4d2da9e0aba211e53a3d040bcccc87f87 (diff)
downloadQt-c6d4a2ca73ac57d47adee35d0d11c98c8b5130ee.zip
Qt-c6d4a2ca73ac57d47adee35d0d11c98c8b5130ee.tar.gz
Qt-c6d4a2ca73ac57d47adee35d0d11c98c8b5130ee.tar.bz2
QKqueueFileSystemWatcherEngine: Unlock mutex between two events.
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 <joao.abecasis@nokia.com>
-rw-r--r--src/corelib/io/qfilesystemwatcher_kqueue.cpp19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp
index 644831b..29cd111 100644
--- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp
+++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp
@@ -237,8 +237,6 @@ void QKqueueFileSystemWatcherEngine::stop()
void QKqueueFileSystemWatcherEngine::run()
{
- static const struct timespec ZeroTimeout = { 0, 0 };
-
forever {
int r;
struct kevent kev;
@@ -247,10 +245,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;
@@ -282,6 +277,8 @@ void QKqueueFileSystemWatcherEngine::run()
break;
}
} else {
+ QMutexLocker locker(&mutex);
+
int id = fd;
QString path = idToPath.value(id);
if (path.isEmpty()) {
@@ -290,12 +287,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) {
@@ -318,11 +315,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);
+ }
}
}