Sfoglia il codice sorgente

Make insert thread safe

Marco Nolden 13 anni fa
parent
commit
043cd0b7bf

+ 7 - 0
Libs/DICOM/Core/ctkDICOMDatabase.cpp

@@ -33,6 +33,7 @@
 #include <QFileInfo>
 #include <QDebug>
 #include <QFileSystemWatcher>
+#include <QMutexLocker>
 
 // ctkDICOM includes
 #include "ctkDICOMDatabase.h"
@@ -101,6 +102,10 @@ public:
   QString LastStudyInstanceUID;
   QString LastSeriesInstanceUID;
   int LastPatientUID;
+
+  /// parallel inserts are not allowed (yet)
+  QMutex insertMutex;
+
   int insertPatient(const ctkDICOMDataset& ctkDataset);
   void insertStudy(const ctkDICOMDataset& ctkDataset, int dbPatientID);
   void insertSeries( const ctkDICOMDataset& ctkDataset, QString studyInstanceUID);
@@ -647,6 +652,8 @@ void ctkDICOMDatabasePrivate::insert( const ctkDICOMDataset& ctkDataset, const Q
 {
   Q_Q(ctkDICOMDatabase);
 
+  QMutexLocker lock(&insertMutex);
+
   // Check to see if the file has already been loaded
   // TODO:
   // It could make sense to actually remove the dataset and re-add it. This needs the remove

+ 56 - 0
Libs/DICOM/Core/ctkDICOMIndexerPrivate.h

@@ -0,0 +1,56 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) German Cancer Research Center
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef CTKDICOMINDEXERPRIVATE_H
+#define CTKDICOMINDEXERPRIVATE_H
+
+#include <QObject>
+
+#include "ctkDICOMIndexer.h"
+
+//------------------------------------------------------------------------------
+class ctkDICOMIndexerPrivate : public QObject
+{
+  Q_OBJECT
+
+  Q_DECLARE_PUBLIC(ctkDICOMIndexer);
+
+protected:
+  ctkDICOMIndexer* const q_ptr;
+
+public:
+  ctkDICOMIndexerPrivate(ctkDICOMIndexer&);
+  ~ctkDICOMIndexerPrivate();
+
+public Q_SLOTS:
+
+  void OnProgress(int progress);
+public:
+
+  ctkDICOMAbstractThumbnailGenerator* thumbnailGenerator;
+  bool                    Canceled;
+  QStringList FilesToIndex;
+  QFutureWatcher<void> DirectoryImportWatcher;
+  QFuture<void> DirectoryImportFuture;
+  int CurrentPercentageProgress;
+};
+
+
+#endif // CTKDICOMINDEXERPRIVATE_H