@@ -110,7 +110,7 @@ void QDltFile::setDltIndex(QVector<qint64> &_indexAll, int num)
110110 bumpSearchSnapshotGenerationLocked ();
111111}
112112
113- int QDltFile::size () const
113+ int QDltFile::sizeLocked () const
114114{
115115 int size=0 ;
116116 for (int num=0 ;num<files.size ();num++)
@@ -122,8 +122,15 @@ int QDltFile::size() const
122122 return size;
123123}
124124
125+ int QDltFile::size () const
126+ {
127+ QMutexLocker locker (&mutexQDlt);
128+ return sizeLocked ();
129+ }
130+
125131qint64 QDltFile::fileSize () const
126132{
133+ QMutexLocker locker (&mutexQDlt);
127134 qint64 size=0 ;
128135
129136 for (int num=0 ;num<files.size ();num++)
@@ -141,11 +148,7 @@ int QDltFile::sizeFilter() const
141148 if (filterFlag)
142149 return indexFilter.size ();
143150
144- int total = 0 ;
145- for (int num = 0 ; num < files.size (); ++num)
146- total += files[num]->indexAll .size ();
147-
148- return total;
151+ return sizeLocked ();
149152}
150153
151154int QDltFile::calculateHeaderSize (quint8 htyp)
@@ -203,13 +206,20 @@ bool QDltFile::open(QString _filename, bool append)
203206
204207 /* create new file item */
205208 QDltFileItem *item = new QDltFileItem ();
206- files.append (item);
207209
208210 /* set new filename */
209211 item->infile .setFileName (_filename);
210212
211213 /* open the log file read only */
212- if (item->infile .open (QIODevice::ReadOnly)==false )
214+ const bool opened = item->infile .open (QIODevice::ReadOnly);
215+
216+ {
217+ QMutexLocker locker (&mutexQDlt);
218+ files.append (item);
219+ bumpSearchSnapshotGenerationLocked ();
220+ }
221+
222+ if (!opened)
213223 {
214224 /* open file failed */
215225 qWarning () << " open of file" << _filename << " failed" ;
@@ -638,6 +648,7 @@ void QDltFile::addFilterIndex (int index)
638648
639649QString QDltFile::getFileName (int num)
640650{
651+ QMutexLocker locker (&mutexQDlt);
641652 if (num<0 || num>=files.size ())
642653 return QString ();
643654
@@ -646,6 +657,7 @@ QString QDltFile::getFileName(int num)
646657
647658int QDltFile::getFileMsgNumber (int num) const
648659{
660+ QMutexLocker locker (&mutexQDlt);
649661 if (num<0 || num>=files.size ())
650662 return -1 ;
651663
@@ -663,6 +675,12 @@ void QDltFile::close()
663675}
664676
665677QByteArray QDltFile::getMsg (int index) const
678+ {
679+ QMutexLocker locker (&mutexQDlt);
680+ return getMsgLocked (index);
681+ }
682+
683+ QByteArray QDltFile::getMsgLocked (int index) const
666684{
667685 QByteArray buf;
668686 int num = 0 ;
@@ -702,8 +720,6 @@ QByteArray QDltFile::getMsg(int index) const
702720 return QByteArray ();
703721 }
704722
705- mutexQDlt.lock ();
706-
707723 QDltFileItem* file = files[num];
708724 const QDltFileItem* const_file = file;
709725 qint64 positionForIndex = const_file->indexAll [index];
@@ -712,7 +728,6 @@ QByteArray QDltFile::getMsg(int index) const
712728 if ( false == file->infile .seek (positionForIndex) )
713729 {
714730 qDebug () << " Seek error on " << positionForIndex << file->infile .fileName () << __FILE__ << __LINE__;
715- mutexQDlt.unlock ();
716731 buf.clear ();
717732 return buf;
718733 }
@@ -738,8 +753,6 @@ QByteArray QDltFile::getMsg(int index) const
738753 buf = file->infile .read (cal_index);
739754 }
740755
741- mutexQDlt.unlock ();
742-
743756 /* return DLT message buffer */
744757 return buf;
745758}
@@ -1003,7 +1016,8 @@ QVector<qint64> QDltFile::mergeIndexFilterBaseWithMarkers(const QSet<qint64> &ma
10031016 if (markerSet.isEmpty ())
10041017 return indexFilterBase;
10051018
1006- const qint64 maxIdx = static_cast <qint64>(size ());
1019+ // Called under mutexQDlt via recomputeEffectiveIndexFilterLocked(); use lock-free helpers.
1020+ const qint64 maxIdx = static_cast <qint64>(sizeLocked ());
10071021
10081022 // Fast membership check: which indices are already present in the base filter output.
10091023 QSet<qint64> present;
@@ -1047,7 +1061,7 @@ QVector<qint64> QDltFile::mergeIndexFilterBaseWithMarkers(const QSet<qint64> &ma
10471061
10481062 if (idx >= 0 && idx < maxIdx && (sortByTime || sortByTimestamp))
10491063 {
1050- const QByteArray data = getMsg (static_cast <int >(idx));
1064+ const QByteArray data = getMsgLocked (static_cast <int >(idx));
10511065 if (!data.isEmpty ())
10521066 {
10531067 QDltMsg msg;
0 commit comments