diff options
Diffstat (limited to 'src/mirall/inotify.cpp')
-rw-r--r-- | src/mirall/inotify.cpp | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/mirall/inotify.cpp b/src/mirall/inotify.cpp index 737492c46..f47e39857 100644 --- a/src/mirall/inotify.cpp +++ b/src/mirall/inotify.cpp @@ -11,6 +11,7 @@ http://www.gnu.org/licenses/gpl.txt . #include <cerrno> #include <unistd.h> #include <QDebug> +#include <QMutexLocker> #include <QStringList> #include "inotify.h" @@ -24,6 +25,7 @@ namespace Mirall { // Allocate space for static members of class. int INotify::s_fd; INotify::INotifyThread* INotify::s_thread; +QMutex INotify::INotifyThread::s_mutex; //INotify::INotify(int wd) : _wd(wd) //{ @@ -46,6 +48,7 @@ INotify::~INotify() void INotify::addPath(const QString &path) { + //QMutexLocker locker(&INotifyThread::s_mutex); // Add an inotify watch. path.toAscii().constData(); @@ -58,6 +61,7 @@ void INotify::addPath(const QString &path) void INotify::removePath(const QString &path) { + QMutexLocker locker(&INotifyThread::s_mutex); // Remove the inotify watch. inotify_rm_watch(s_fd, _wds[path]); _wds.remove(path); @@ -72,6 +76,7 @@ void INotify::INotifyThread::unregisterForNotification(INotify* notifier) { //_map.remove(notifier->_wd); + //QMutexLocker locker(&INotifyThread::s_mutex); QHash<int, INotify*>::iterator it; for (it = _map.begin(); it != _map.end(); ++it) { if (it.value() == notifier) @@ -82,14 +87,18 @@ INotify::INotifyThread::unregisterForNotification(INotify* notifier) void INotify::INotifyThread::registerForNotification(INotify* notifier, int wd) { + //QMutexLocker locker(&INotifyThread::s_mutex); _map[wd] = notifier; } void INotify::fireEvent(int mask, int cookie, int wd, char* name) { - QString path; - foreach (path, _wds.keys(wd)) + //qDebug() << "****" << name; + //QMutexLocker locker(&INotifyThread::s_mutex); + + QStringList paths(_wds.keys(wd)); + foreach (QString path, paths) emit notifyEvent(mask, cookie, path + "/" + QString::fromUtf8(name)); } @@ -170,12 +179,25 @@ INotify::INotifyThread::run() continue; } n = _map[event->wd]; + // dont allow addPath removePath clash here + { + //QThread::msleep(100); + // fire event + if (event->len > 0) { + //QMutexLocker locker(&s_mutex); + if (n) + n->fireEvent(event->mask, event->cookie, event->wd, event->name); + else + { + qWarning() << "n is NULL"; + } + + } + + // increment counter + i += sizeof(struct inotify_event) + event->len; + } - // fire event - if (event->len > 0) - n->fireEvent(event->mask, event->cookie, event->wd, event->name); - // increment counter - i += sizeof(struct inotify_event) + event->len; } } } |