From: <ai...@us...> - 2009-03-21 15:39:12
|
Revision: 9765 http://plplot.svn.sourceforge.net/plplot/?rev=9765&view=rev Author: airwin Date: 2009-03-21 15:39:08 +0000 (Sat, 21 Mar 2009) Log Message: ----------- AWI for Alban Rochel. - Introduce a mutex to make driver thread safe. Andrew noticed that when 2 qtwidgets were running on 2 streams, closing them didn't close the driver properly. This issue should be fixed by this change. Modified Paths: -------------- trunk/drivers/qt.cpp trunk/drivers/qt.h Modified: trunk/drivers/qt.cpp =================================================================== --- trunk/drivers/qt.cpp 2009-03-21 00:53:53 UTC (rev 9764) +++ trunk/drivers/qt.cpp 2009-03-21 15:39:08 UTC (rev 9765) @@ -71,6 +71,7 @@ void initQtApp(bool isGUI) { + QtPLDriver::mutex.lock(); ++appCounter; if(qApp==NULL && appCounter==1) { @@ -82,10 +83,12 @@ argv[1][0]='\0'; /*app=*/new QApplication(argc, argv, isGUI ); } + QtPLDriver::mutex.unlock(); } void closeQtApp() { + QtPLDriver::mutex.lock(); --appCounter; if(qApp!=NULL && appCounter==0) { @@ -96,6 +99,7 @@ delete[] argv; argv=NULL; } + QtPLDriver::mutex.unlock(); } /*--------------------------------------------------------------------- @@ -1465,6 +1469,21 @@ widgets.push_back(plotWidget); } +void QtPLTabWidget::exec() +{ + mutex.lock(); + if(!alreadyRun) // This tab widget has never been run + { + qApp->exec(); + foreach(QtPLTabWidget* tab, runningDevices) // All the tab widgets created before have been run in the same time. Let's tag them. + { + tab->alreadyRun=true; + } + + } + runningDevices.removeAll(this); // cleaning up + mutex.unlock(); +} void plD_dispatch_init_qtwidget(PLDispatchTable *pdt) { @@ -1547,11 +1566,11 @@ void plD_tidy_qtwidget(PLStream *pls) { - qApp->exec(); + QtPLTabWidget * w=((QtPLTabWidget*)pls->dev); + w->exec(); + // At this point, the widget has been run, we can delete it delete ((QtPLTabWidget*)pls->dev); pls->dev=NULL; - -// closeQtApp(); } #endif Modified: trunk/drivers/qt.h =================================================================== --- trunk/drivers/qt.h 2009-03-21 00:53:53 UTC (rev 9764) +++ trunk/drivers/qt.h 2009-03-21 15:39:08 UTC (rev 9765) @@ -53,6 +53,7 @@ #include <QTabWidget> #include <QMainWindow> #include <QPicture> +#include <QMutex> #include "plplotP.h" #include "drivers.h" @@ -91,6 +92,8 @@ // Conversion factor from internal plplot coordinates to device coordinates double downscale; double m_dWidth, m_dHeight; + + static QMutex mutex; // All-purpose mutex protected: // Returns font with the good size for a QPicture's resolution @@ -113,6 +116,8 @@ QPainter* m_painterP; }; +QMutex QtPLDriver::mutex; + #if defined (PLD_bmpqt) || defined(PLD_jpgqt) || defined (PLD_pngqt) || defined(PLD_ppmqt) || defined(PLD_tiffqt) // Driver painting whatever raster format Qt can save class QtRasterDevice: public QtPLDriver, public QImage @@ -263,6 +268,11 @@ m_iWidth=i_iWidth; m_iHeight=i_iHeight; currentWidget=NULL; + + mutex.lock(); // All QtPLTabWidgets are registered + alreadyRun=false; + runningDevices.push_back(this); + mutex.unlock(); } ~QtPLTabWidget(); @@ -324,10 +334,15 @@ virtual void savePlot(char* fileName){} + void exec(); + QtPLWidget* currentWidget; int m_iWidth, m_iHeight; + static QList<QtPLTabWidget*> runningDevices; + bool alreadyRun; + protected: void newTab(); QList<QtPLWidget*> widgets; @@ -337,6 +352,8 @@ }; +QList<QtPLTabWidget*> QtPLTabWidget::runningDevices; + #endif #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |