summaryrefslogtreecommitdiffstats
path: root/smdirwatcher.h
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2013-08-28 09:32:30 +0200
committerArno <am@disconnect.de>2013-08-28 09:32:30 +0200
commit1ee897fbb51cb431cba7690076a29a3ca2ddc1a7 (patch)
tree127c2ff9ff239e672159d44aa161e99ec222898c /smdirwatcher.h
parentdbfc4f7bf395bf20aa21058372d47d17d040f553 (diff)
downloadSheMov-1ee897fbb51cb431cba7690076a29a3ca2ddc1a7.tar.gz
SheMov-1ee897fbb51cb431cba7690076a29a3ca2ddc1a7.tar.bz2
SheMov-1ee897fbb51cb431cba7690076a29a3ca2ddc1a7.zip
Fix crashes in SmDirWatcher (again)
This reverts commit dbfc4f7bf395bf20aa21058372d47d17d040f553. It was totally and utterly wrong. This is what really happened, hopefully: Since a Semaphore can guard more than a single resource, it could happen that both mSemUsed and mSemFree were available at the same time. So it could happen that both the watcher and the datacollector tried to access the dataqueue at the same time. Since ->dequeue() is not atomic, this could throw of the internal iterator from the QList, resulting in a crash. The solution is simple: Guard it with a shared Mutex.
Diffstat (limited to 'smdirwatcher.h')
-rw-r--r--smdirwatcher.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/smdirwatcher.h b/smdirwatcher.h
index 77d0d97..fda828b 100644
--- a/smdirwatcher.h
+++ b/smdirwatcher.h
@@ -45,6 +45,7 @@ class SmDirWatcher : public QThread {
QSemaphore *mSemFree;
QSemaphore *mSemUsed;
QQueue<QPair<QString, DWEvent> > *mDataQueue;
+ QMutex *mQueueMx;
char *mINdata;
int mBufLen;
};
@@ -53,7 +54,7 @@ class SmDataColletor : public QThread {
Q_OBJECT
public:
explicit SmDataColletor(const int numFields, QObject *parent = 0);
- void init(QSemaphore *set, QSemaphore *get, QQueue<QPair<QString, SmDirWatcher::DWEvent> > *data);
+ void init(QSemaphore *set, QSemaphore *get, QQueue<QPair<QString, SmDirWatcher::DWEvent> > *data, QMutex *queueMx);
public slots:
void setCheckForPresent(bool present);
@@ -71,6 +72,7 @@ class SmDataColletor : public QThread {
QString mCurrent;
QSemaphore *mSemFree;
QSemaphore *mSemUsed;
+ QMutex *mQueueMx;
QQueue<QPair<QString, SmDirWatcher::DWEvent> > *mDataQueue;
int mMode;
const int mNumFields;