From 1ee897fbb51cb431cba7690076a29a3ca2ddc1a7 Mon Sep 17 00:00:00 2001 From: Arno Date: Wed, 28 Aug 2013 09:32:30 +0200 Subject: 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. --- smdirwatcher.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'smdirwatcher.h') 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 > *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 > *data); + void init(QSemaphore *set, QSemaphore *get, QQueue > *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 > *mDataQueue; int mMode; const int mNumFields; -- cgit v1.2.3-70-g09d2