[Kst] extragear/graphics/kst/kst

George Staikos staikos at kde.org
Fri Feb 3 04:20:45 CET 2006


SVN commit 505102 by staikos:

fix deadlock and race conditions


 M  +54 -51    kstchangenptsdialog_i.cpp  
 M  +3 -1      kstchangenptsdialog_i.h  


--- trunk/extragear/graphics/kst/kst/kstchangenptsdialog_i.cpp #505101:505102
@@ -19,6 +19,7 @@
 #include <qlistbox.h>
 #include <qpushbutton.h>
 #include <qspinbox.h>
+#include <qtimer.h>
 
 #include <kcombobox.h>
 #include <knuminput.h>
@@ -66,18 +67,18 @@
   
   KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
   // insert vectors into ChangeNptsCurveList
-  for (uint i = 0; i < rvl.count(); i++) {
-    KstRVectorPtr vector = rvl[i];
-    if (vector) {
-      vector->readLock();
-      CurveList->insertItem(vector->tagName(), -1);
-      if (qsl.contains(vector->tagName())) {
-        CurveList->setSelected(inserted, true);
-      }
-      inserted++;
-      vector->readUnlock();
+  CurveList->blockSignals(true); // avoid deadlock
+  for (KstRVectorList::ConstIterator i = rvl.begin(); i != rvl.end(); ++i) {
+    KstRVectorPtr vector = *i;
+    vector->readLock();
+    CurveList->insertItem(vector->tagName(), -1);
+    if (qsl.contains(vector->tagName())) {
+      CurveList->setSelected(inserted, true);
     }
+    ++inserted;
+    vector->readUnlock();
   }
+  CurveList->blockSignals(false);
   return !qsl.isEmpty();
 }
 
@@ -102,33 +103,31 @@
         int f0, n;
         
         vector->readLock();
-        if (_kstDataRange->isStartRelativeTime() && vector->dataSource()) {
-          vector->dataSource()->readLock();
-          f0 = vector->dataSource()->sampleForTime(_kstDataRange->f0Value());
-          vector->dataSource()->readUnlock();
-        } else if (_kstDataRange->isStartAbsoluteTime() && vector->dataSource()) {
-          vector->dataSource()->readLock();
-          f0 = vector->dataSource()->sampleForTime(_kstDataRange->f0DateTimeValue());
-          vector->dataSource()->readUnlock();
+        KstDataSourcePtr ds = vector->dataSource();
+        if (_kstDataRange->isStartRelativeTime() && ds) {
+          ds->readLock();
+          f0 = ds->sampleForTime(_kstDataRange->f0Value());
+          ds->readUnlock();
+        } else if (_kstDataRange->isStartAbsoluteTime() && ds) {
+          ds->readLock();
+          f0 = ds->sampleForTime(_kstDataRange->f0DateTimeValue());
+          ds->readUnlock();
         } else {
           f0 = int(_kstDataRange->f0Value());
         }
       
-        if (_kstDataRange->isRangeRelativeTime() && vector->dataSource()) {
-          KstDataSourcePtr ds = vector->dataSource();
-          if (ds) {
-            ds->readLock();
-            double nValStored = _kstDataRange->nValue();
-            if (_kstDataRange->CountFromEnd->isChecked()) {
-              int frameCount = ds->frameCount(vector->field());
-              double msCount = ds->relativeTimeForSample(frameCount - 1);
-              n = frameCount - 1 - ds->sampleForTime(msCount - nValStored);
-            } else {
-              double fTime = ds->relativeTimeForSample(f0);
-              n = ds->sampleForTime(fTime + nValStored) - ds->sampleForTime(fTime);
-            }
-            ds->readUnlock();
+        if (_kstDataRange->isRangeRelativeTime() && ds) {
+          ds->readLock();
+          double nValStored = _kstDataRange->nValue();
+          if (_kstDataRange->CountFromEnd->isChecked()) {
+            int frameCount = ds->frameCount(vector->field());
+            double msCount = ds->relativeTimeForSample(frameCount - 1);
+            n = frameCount - 1 - ds->sampleForTime(msCount - nValStored);
+          } else {
+            double fTime = ds->relativeTimeForSample(f0);
+            n = ds->sampleForTime(fTime + nValStored) - ds->sampleForTime(fTime);
           }
+          ds->readUnlock();
         } else {
           n = int(_kstDataRange->nValue());
         }
@@ -146,39 +145,43 @@
     }
   }
 
+  // avoid re-entering the dialog
+  QTimer::singleShot(0, this, SLOT(emitDocChanged()));
+}
+
+
+void KstChangeNptsDialogI::emitDocChanged() {
   emit docChanged();
 }
 
 
 void KstChangeNptsDialogI::updateDefaults(int index) {
   KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
-  if (rvl.isEmpty() || index >= (int)rvl.count()) {
+  if (rvl.isEmpty() || index >= (int)rvl.count() || index < 0) {
     return;
   }
 
   KstRVectorPtr vector = rvl[index];
-  if (vector) {
-    vector->writeLock();
+  vector->readLock();
 
-    _kstDataRange->_startUnits->setCurrentItem(0);
-    _kstDataRange->_rangeUnits->setCurrentItem(0);
+  _kstDataRange->_startUnits->setCurrentItem(0);
+  _kstDataRange->_rangeUnits->setCurrentItem(0);
 
-    /* fill the vector range entries */
-    _kstDataRange->CountFromEnd->setChecked(vector->countFromEOF());
-    _kstDataRange->setF0Value(vector->reqStartFrame());
+  /* fill the vector range entries */
+  _kstDataRange->CountFromEnd->setChecked(vector->countFromEOF());
+  _kstDataRange->setF0Value(vector->reqStartFrame());
 
-    /* fill number of frames entries */
-    _kstDataRange->ReadToEnd->setChecked(vector->readToEOF());
-    _kstDataRange->setNValue(vector->reqNumFrames());
+  /* fill number of frames entries */
+  _kstDataRange->ReadToEnd->setChecked(vector->readToEOF());
+  _kstDataRange->setNValue(vector->reqNumFrames());
 
-    /* fill in frames to skip box */
-    _kstDataRange->Skip->setValue(vector->skip());
-    _kstDataRange->DoSkip->setChecked(vector->doSkip());
-    _kstDataRange->DoFilter->setChecked(vector->doAve());
-    _kstDataRange->updateEnables();
-    
-    vector->writeUnlock();
-  }
+  /* fill in frames to skip box */
+  _kstDataRange->Skip->setValue(vector->skip());
+  _kstDataRange->DoSkip->setChecked(vector->doSkip());
+  _kstDataRange->DoFilter->setChecked(vector->doAve());
+  _kstDataRange->updateEnables();
+
+  vector->readUnlock();
 }
 
 
--- trunk/extragear/graphics/kst/kst/kstchangenptsdialog_i.h #505101:505102
@@ -43,6 +43,7 @@
   void updateDefaults(int index=0);
 
 private slots:
+  void emitDocChanged();
   void applyNptsChange();
   void updateTimeCombo();
 
@@ -52,4 +53,5 @@
 };
 
 
-#endif // KSTCHANGENPTSDIALOGI_H
+#endif
+// vim: ts=2 sw=2 et


More information about the Kst mailing list