Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
authorgiersch <giersch>
Mon, 5 Nov 2007 20:40:52 +0000 (20:40 +0000)
committergiersch <giersch>
Mon, 5 Nov 2007 20:40:52 +0000 (20:40 +0000)
DrawingWindow.cpp
DrawingWindow.h
test/hello.cpp

index eb14102..4e34d9e 100644 (file)
@@ -3,6 +3,8 @@
 #include <QThread>
 #include <QTimerEvent>
 
+#include <iostream>
+
 class DrawingWindow::DrawingThread: public QThread {
 public:
     DrawingThread(DrawingWindow &w, ThreadFunction f)
@@ -13,7 +15,7 @@ public:
 
     void run()
     {
-        exit(threadFunction(drawingWindow));
+        threadFunction(drawingWindow);
     }
 
 private:
@@ -59,13 +61,24 @@ void DrawingWindow::initialize(ThreadFunction fun, int width, int height)
 
     thread = new DrawingThread(*this, fun);
     thread_started = false;
+
+    mutex_enabled = true;
 }
 
 DrawingWindow::~DrawingWindow()
 {
+    mutex.lock();
+    mutex_enabled = false;
+    mutex.unlock();
+    std::cerr << "A\n";
+    thread->terminate();    
+    std::cerr << "B\n";
+    thread->wait();
+    std::cerr << "C\n";
     delete thread;
     delete painter;
     delete image;
+    std::cerr << "D\n";
 }
 
 void DrawingWindow::setColor(const QColor &color)
index 7291e96..9e86889 100644 (file)
@@ -14,7 +14,7 @@ class DrawingWindow: public QWidget {
 /*     Q_OBJECT */
 
 public:
-    typedef int (*ThreadFunction)(DrawingWindow &);
+    typedef void (*ThreadFunction)(DrawingWindow &);
 
     static const int DEFAULT_WIDTH = 640;
     static const int DEFAULT_HEIGHT = 480;
@@ -60,6 +60,7 @@ private:
     bool dirtyFlag;
     QRect dirtyRect;
 
+    bool mutex_enabled;
     QMutex mutex;
 
     void initialize(ThreadFunction fun, int width, int height);
@@ -88,7 +89,10 @@ int DrawingWindow::height() const
 inline
 void DrawingWindow::lock()
 {
-    mutex.lock();
+    if (mutex_enabled)
+        mutex.lock();
+    if (!mutex_enabled)
+        mutex.unlock();
 }
 
 inline
index cf598aa..8c1585c 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <iostream>
 
-int flip(DrawingWindow &w)
+void flip(DrawingWindow &w)
 {
     std::cout << "[ " << w.width() << " x " << w.height() << " ]\n";
 
@@ -50,10 +50,9 @@ int flip(DrawingWindow &w)
 //                       << y << " (" << c << ")\n";
         }
     }
-    return 0;
 }
 
-int mandel(DrawingWindow &w)
+void mandel(DrawingWindow &w)
 {
     /* paramètres par défaut */
     int larg = w.width();
@@ -116,10 +115,9 @@ int mandel(DrawingWindow &w)
         }
         cr += pr;
     }
-    return 0;
 }
 
-int lines(DrawingWindow &w)
+void lines(DrawingWindow &w)
 {
     int n = 100000;
     int xmax = w.width();
@@ -135,7 +133,6 @@ int lines(DrawingWindow &w)
         w.setColor(r, g, b);
         w.drawLine(x1, y1, x2, y2);
     }
-    return 0;
 }
 
 int main(int argc, char *argv[])