[Kst] kdeextragear-2/kst/kst

Andrew Walker arwalker at sumusltd.com
Thu Apr 8 21:07:35 CEST 2004


CVS commit by arwalker: 

Provide a more efficient way to terminate the update thread
Respect the plot update timer value


  M +2 -2      kst.cpp   1.96
  M +25 -6     updatethread.cpp   1.8
  M +4 -2      updatethread.h   1.3


--- kdeextragear-2/kst/kst/kst.cpp  #1.95:1.96
@@ -123,5 +123,5 @@ KstApp::KstApp(QWidget *parent, const ch
 
   _updateThread = new UpdateThread(doc);
-  // FIXME XXXX KstSettings::globalSettings()->plotUpdateTimer;
+  _updateThread->setUpdateTime(KstSettings::globalSettings()->plotUpdateTimer);
   _updateThread->start();
 
@@ -1034,5 +1034,5 @@ void KstApp::slotPreferences() {
 
 void KstApp::slotSettingsChanged() {
-  // FIXME XXXX KstSettings::globalSettings()->plotUpdateTimer
+  _updateThread->setUpdateTime(KstSettings::globalSettings()->plotUpdateTimer);
 }
 

--- kdeextragear-2/kst/kst/updatethread.cpp  #1.7:1.8
@@ -42,9 +42,21 @@ UpdateThread::~UpdateThread() {
 
 void UpdateThread::run() {
-  // FIXME XXXX remove me when the rest of the code is threadsafe
-  QThread::sleep(5);
+  bool force;
+  int  updateTime;
+  
+  _done = false;
+  
+  while( !_done ) {
+    _statusMutex.lock();
+    updateTime = _updateTime;
+    _statusMutex.unlock();
+    
+    if( _waitCondition.wait( _updateTime ) ) {
+#if UPDATEDEBUG > 0
+      kdDebug() << "Update timer" << _updateTime << endl;
+#endif
+      break;
+    }
 
-  // FIXME: make msleep() configurable here
-  for (_done = false; !_done; QThread::msleep(50)) {
     if (_paused) {
 #if UPDATEDEBUG > 0
@@ -54,5 +66,5 @@ void UpdateThread::run() {
     }
 
-    bool force = _force;
+    force = _force;
 
     _statusMutex.lock();
@@ -208,4 +220,10 @@ bool UpdateThread::doUpdates(bool force)
 
 
+void UpdateThread::setUpdateTime(int updateTime) {
+  QMutexLocker ml(&_statusMutex);
+  _updateTime = updateTime;
+}
+
+
 void UpdateThread::setPaused(bool paused) {
   QMutexLocker ml(&_statusMutex);
@@ -217,4 +235,5 @@ void UpdateThread::setFinished(bool fini
   QMutexLocker ml(&_statusMutex);
   _done = finished;
+  _waitCondition.wakeOne();
 }
 

--- kdeextragear-2/kst/kst/updatethread.h  #1.2:1.3
@@ -21,4 +21,5 @@
 #include <qmutex.h>
 #include <qthread.h>
+#include <qwaitcondition.h>
 
 class KstDoc;
@@ -30,7 +31,6 @@ class UpdateThread : public QThread {
 
     void setPaused(bool paused);
-
     void setFinished(bool finished);
-
+    void setUpdateTime(int updateTime);
     void forceUpdate();
 
@@ -42,7 +42,9 @@ class UpdateThread : public QThread {
   private:
     bool _paused, _done;
+    QWaitCondition _waitCondition;
     QMutex _statusMutex;
     KstDoc *_doc;
     int _updateCounter;
+    int _updateTime;
     bool _force;
 };





More information about the Kst mailing list