diff options
author | Arno <am@disconnect.de> | 2013-09-14 13:01:21 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2013-09-14 13:01:21 +0200 |
commit | 612776e7976f1a901849c61ae9142dd49b8e3f5c (patch) | |
tree | 9244987862d4b5f462bfb621d39d8bd2b5c29a95 /smdirwatcher.cpp | |
parent | ab474b97614825636831a81c7ea8097ef7b14af9 (diff) | |
download | SheMov-612776e7976f1a901849c61ae9142dd49b8e3f5c.tar.gz SheMov-612776e7976f1a901849c61ae9142dd49b8e3f5c.tar.bz2 SheMov-612776e7976f1a901849c61ae9142dd49b8e3f5c.zip |
Behave on qApp->quit()
Sometimes there was a warning that a thread was being destroyed while
still running. This was SmDirWatcher::run(). read() blocks until new
data is ready, so run() never exited.
Fix it by poll()ing the inotify_descriptor. Return immediately if no
data is ready.
Also fix a small memory leak. Delete ConsistencyChecker when the dialog
is destructed.
Diffstat (limited to 'smdirwatcher.cpp')
-rw-r--r-- | smdirwatcher.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/smdirwatcher.cpp b/smdirwatcher.cpp index 038c4cf..5b4f42a 100644 --- a/smdirwatcher.cpp +++ b/smdirwatcher.cpp @@ -11,6 +11,7 @@ #include <sys/inotify.h> #include <unistd.h> +#include <poll.h> #include "smdirmodel.h" #include "smdirwatcher.h" @@ -116,6 +117,14 @@ QList<QVariant> SmDirWatcher::generalData(const QString &path){ } void SmDirWatcher::run(){ + struct pollfd pfd[1]; + pfd[0].fd = mFd; + pfd[0].events = POLLIN; + pfd[0].revents = 0; + int pr = poll(pfd, 1, 0); + if(pr <= 0){ + return; + } int r = read(mFd, mINdata, mBufLen); if(r <= 0){ return; @@ -145,6 +154,7 @@ void SmDirWatcher::run(){ void SmDirWatcher::stop(){ quit(); + wait(); } AsyncTask::AsyncTask(const QString &path) : mSkip(false), mPath(path) {} |