[Kst] kdeextragear-2/kst/kst [POSSIBLY UNSAFE]

Barth Netterfield netterfield at astro.utoronto.ca
Fri Jun 25 21:51:20 CEST 2004


CVS commit by netterfield: 

The update thread can run much faster than the UI thread in many real time cases.
This fix causes the update thread to wait for the UI thread to finish painting
before submitting the next update event.


  M +8 -3      kstdoc.cpp   1.91
  M +5 -3      kstdoc.h   1.29
  M +23 -7     updatethread.cpp   1.17 [POSSIBLY UNSAFE: printf]


--- kdeextragear-2/kst/kst/kstdoc.cpp  #1.90:1.91
@@ -77,4 +77,5 @@ KstDoc::KstDoc(QWidget *parent, const ch
 : QObject(parent, name) {
   _lock = 0;
+  _updateing = false;
   stopping = false;
 }
@@ -767,4 +768,6 @@ bool KstDoc::event(QEvent *e) {
 
   if (e->type() == KstEventTypeThread) {
+    _updateing = true; // block update thread from sending events 'till we're done
+
     ThreadEvent *te = static_cast<ThreadEvent*>(e);
     if (te->_eventType == ThreadEvent::UpdateDialogs) {
@@ -790,4 +793,6 @@ bool KstDoc::event(QEvent *e) {
     } else if (te->_eventType == ThreadEvent::Done) {
     }
+    _updateing = false; // ok, we're done...
+
     return true;
   }

--- kdeextragear-2/kst/kst/kstdoc.h  #1.28:1.29
@@ -74,4 +74,6 @@ public:
   virtual bool event(QEvent *e);
 
+  bool updateing() { return _updateing;}
+
 public slots:
   void purge();
@@ -110,5 +112,5 @@ private:
   QString absFilePath;
   int _lock;
-
+  bool _updateing;
 signals:
   /** if something has changed the vectors */

--- kdeextragear-2/kst/kst/updatethread.cpp  #1.16:1.17
@@ -80,4 +80,19 @@ void UpdateThread::run() {
       kdDebug() << "Update resulted in: TRUE!" << endl;
 #endif
+      // Wait for UI thread to finish events.  This is a
+      // a hack to keep update thread from getting ahead of the UI thread,
+      // which would block UI thread by filling it with un-processable requests.
+      bool do_wait=false;
+      while (_doc->updateing()) {
+        do_wait = true;
+        printf("waiting for UI thread\n");
+        usleep(1000);
+      }
+      if (do_wait) usleep(1000);
+      while (_doc->updateing()) { // check again...
+        printf("waiting for UI thread\n");
+        usleep(1000);
+      }
+
       QApplication::postEvent(_doc, new ThreadEvent(ThreadEvent::UpdateDialogs));
       QApplication::postEvent(_doc, new ThreadEvent(ThreadEvent::Repaint));





More information about the Kst mailing list