summaryrefslogtreecommitdiffstats
path: root/src/corelib
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 16:08:10 (GMT)
commite0e9d4ea2cec37243d964a5309be49101d112233 (patch)
treeb4514dcaf5a46d57337739bbb5d8c740784f3c26 /src/corelib
parent03c82dc0d4b4bbbe17e9d91bef6a112d512ca002 (diff)
downloadQt-e0e9d4ea2cec37243d964a5309be49101d112233.zip
Qt-e0e9d4ea2cec37243d964a5309be49101d112233.tar.gz
Qt-e0e9d4ea2cec37243d964a5309be49101d112233.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>
Diffstat (limited to 'src/corelib')
-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 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);
+ }
}
}