From 2ed61565fcc2430b6b3c38cb9df0ff25ff4b4894 Mon Sep 17 00:00:00 2001 From: prascle Date: Mon, 26 Jan 2004 16:42:18 +0000 Subject: [PATCH] PR: Multi Thread and Mutex Qt --- src/SALOMEGUI/Makefile.in | 2 + src/SALOMEGUI/QAD_Application.cxx | 21 +++++++- src/SALOMEGUI/QAD_Application.h | 6 +++ src/SALOMEGUI/QAD_Study.cxx | 8 +++ src/SALOMEGUI/SALOMEGUI_VisuMutex.cxx | 74 ++++++++++++++++++++++++++ src/SALOMEGUI/SALOMEGUI_VisuMutex.hxx | 32 +++++++++++ src/Session/SALOME_Session_QThread.cxx | 4 +- src/Session/SALOME_Session_QThread.hxx | 3 +- src/Session/SALOME_Session_i.cxx | 2 +- 9 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 src/SALOMEGUI/SALOMEGUI_VisuMutex.cxx create mode 100644 src/SALOMEGUI/SALOMEGUI_VisuMutex.hxx diff --git a/src/SALOMEGUI/Makefile.in b/src/SALOMEGUI/Makefile.in index 08d0682d3..ba7a424e4 100644 --- a/src/SALOMEGUI/Makefile.in +++ b/src/SALOMEGUI/Makefile.in @@ -74,6 +74,7 @@ EXPORT_HEADERS = \ SALOMEGUI_Desktop.h \ SALOMEGUI_ImportOperation.h \ SALOMEGUI_ViewChoiceDlg.h \ + SALOMEGUI_VisuMutex.hxx \ SALOMEGUI_Swig.hxx \ SALOMEGUI_Swig.i \ SALOMEGUI_QtCatchCorbaException.hxx \ @@ -159,6 +160,7 @@ LIB_SRC = \ SALOMEGUI_OpenWith.cxx \ SALOMEGUI_StudyPropertiesDlg.cxx \ SALOMEGUI_QtCatchCorbaException.cxx \ + SALOMEGUI_VisuMutex.cxx \ SALOME_ListIO_0.cxx \ SALOME_ListNodeOfListIO_0.cxx \ SALOME_ListIteratorOfListIO_0.cxx \ diff --git a/src/SALOMEGUI/QAD_Application.cxx b/src/SALOMEGUI/QAD_Application.cxx index a0b08aa45..909714d0c 100644 --- a/src/SALOMEGUI/QAD_Application.cxx +++ b/src/SALOMEGUI/QAD_Application.cxx @@ -220,7 +220,8 @@ QAD_Application::QAD_Application( const QString& format, const QString& descript myActiveStudy( 0 ), myStudyFormat( format ), myStudyExtension( extension ), -myStudyDescription( description ) +myStudyDescription( description ), +_GUIMutex(0) { /* actions are stored in vectors only */ @@ -367,6 +368,24 @@ const QPixmap& QAD_Application::getApplicationIcon() const return myIcon; } +/*! + Returns the GUI Mutex +*/ +QMutex* QAD_Application::getGUIMutex() +{ + //SCRUTE(_GUIMutex); + return _GUIMutex; +} + +/*! + Sets the GUI Mutex +*/ +void QAD_Application::setGUIMutex(QMutex* guiMutex) +{ + _GUIMutex = guiMutex; + //SCRUTE(_GUIMutex); +} + /*! Returns the study description */ diff --git a/src/SALOMEGUI/QAD_Application.h b/src/SALOMEGUI/QAD_Application.h index cd6985ae6..82bfb53f0 100644 --- a/src/SALOMEGUI/QAD_Application.h +++ b/src/SALOMEGUI/QAD_Application.h @@ -43,6 +43,7 @@ #include #include #include +#include class QAD_Operation; class QAD_Desktop; @@ -68,6 +69,9 @@ public: const QString& getApplicationName() const; const QPixmap& getApplicationIcon() const; + QMutex* getGUIMutex(); + void setGUIMutex(QMutex* guiMutex); + /* studies management */ const QString& getStudyFormat() const; const QString& getStudyExtension() const; @@ -175,6 +179,8 @@ protected: QString myStudyExtension; QString myStudyDescription; + QMutex* _GUIMutex; + #if defined SOLARIS /* SUN C++ v4.1 compiler BUG ? Error when using protected 'desktop' in subclasses. diff --git a/src/SALOMEGUI/QAD_Study.cxx b/src/SALOMEGUI/QAD_Study.cxx index 0e1796ab3..eb686a5e0 100644 --- a/src/SALOMEGUI/QAD_Study.cxx +++ b/src/SALOMEGUI/QAD_Study.cxx @@ -50,6 +50,7 @@ using namespace std; #include "SALOME_TypeFilter.hxx" #include "SALOME_InteractiveObject.hxx" #include "SALOME_ListIteratorOfListIO.hxx" +#include "SALOMEGUI_VisuMutex.hxx" #include #include CORBA_SERVER_HEADER(SALOMEDS) @@ -948,6 +949,9 @@ void QAD_Study::onLastStudyFrameClosing( QAD_StudyFrame* sf ) */ QAD_StudyFrame* QAD_Study::newWindow3d(QString name, ViewType theViewType, bool toShow) { + QMutex *theGUIMutex = myApp->getGUIMutex(); + //SCRUTE(theGUIMutex); + VISU::Mutex mt(theGUIMutex,qApp); if(name == "") name = getNextStudyFrameName(); QAD_StudyFrame* sf = createStudyFrame( name, theViewType ); if ( myResult ) { @@ -1271,6 +1275,10 @@ int QAD_Study::getStudyId() void QAD_Study::update3dViewers() { + //MESSAGE("QAD_Study::update3dViewers"); + QMutex *theGUIMutex = myApp->getGUIMutex(); + //SCRUTE(theGUIMutex); + VISU::Mutex mt(theGUIMutex,qApp); for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) { sf->getRightFrame()->getViewFrame()->Repaint(); } diff --git a/src/SALOMEGUI/SALOMEGUI_VisuMutex.cxx b/src/SALOMEGUI/SALOMEGUI_VisuMutex.cxx new file mode 100644 index 000000000..2ee92fcb8 --- /dev/null +++ b/src/SALOMEGUI/SALOMEGUI_VisuMutex.cxx @@ -0,0 +1,74 @@ + + +#include "SALOMEGUI_VisuMutex.hxx" +#include "utilities.h" + +using namespace std; + +namespace VISU +{ + static int mySCnt = 0; + static int myQCnt = 0; + //static QMutex localMutex; + //static QMutex localSMutex; + + Mutex::Mutex(QMutex* theMutex, QApplication* theQApp, int theDelay) : + myQApp(theQApp), myDelay(theDelay), myMutex(theMutex) + { + MESSAGE("-+-+-+-"); + isQAppLocked=theQApp->locked(); + isSessionLocked=theMutex->locked(); + MESSAGE(" ===== Mutex::Mutex : "<lock(); + myQApp->syncX(); + myQCnt++; + if (myQCnt > 1) MESSAGE( " --- myQCnt : " << myQCnt); + MESSAGE ("- = - = -"); + } + + Mutex::~Mutex() + { + MESSAGE("~~~~~~~"); + myQCnt--; + myQApp->flushX(); + myQApp->unlock(); + MESSAGE(" ===== Mutex::~Mutex : "<locked(); + MESSAGE(" ///// SMutex::SMutex : "<lock(); + MESSAGE(" ooo 2"); + } + mySCnt++; + if (mySCnt > 1) MESSAGE( " --- mySCnt : " << mySCnt); + //localSMutex.unlock(); + MESSAGE (" ooo 3"); + } + + SMutex::~SMutex() + { + MESSAGE(" _-_ 1"); + //localSMutex.lock(); + mySCnt--; + if(!isSessionLocked && !mySCnt) + { + myMutex->unlock(); + MESSAGE(" _-_ 2"); + } + MESSAGE(" ///// SMutex::~SMutex : "< +#include + +namespace VISU +{ + + class Mutex + { + QMutex* myMutex; + QApplication* myQApp; + int isQAppLocked, isSessionLocked, myDelay; + public: + Mutex(QMutex* theMutex, QApplication* theQApp, int theDelay = 0); + ~Mutex(); + }; + + class SMutex + { + QMutex* myMutex; + QApplication* myQApp; + int isQAppLocked, isSessionLocked, myDelay; + public: + SMutex(QMutex* theMutex, QApplication* theQApp, int theDelay = 0); + ~SMutex(); + }; +} + +#endif diff --git a/src/Session/SALOME_Session_QThread.cxx b/src/Session/SALOME_Session_QThread.cxx index 8531be10f..4e075d495 100644 --- a/src/Session/SALOME_Session_QThread.cxx +++ b/src/Session/SALOME_Session_QThread.cxx @@ -54,13 +54,14 @@ using namespace std; */ //============================================================================= -SALOME_Session_QThread::SALOME_Session_QThread(int argc, char ** argv) : QThread() +SALOME_Session_QThread::SALOME_Session_QThread(int argc, char ** argv, QMutex *theGUIMutex) : QThread() { _qappl = 0 ; _mw = 0 ; _argc = argc ; _argv = argv ; _NS = 0 ; + _GUIMutex = theGUIMutex; } ; //============================================================================= @@ -81,6 +82,7 @@ void SALOME_Session_QThread::run() QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) ); _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" ); INFOS("creation SALOMEGUI_Application"); + _mw->setGUIMutex(_GUIMutex); if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) ) { diff --git a/src/Session/SALOME_Session_QThread.hxx b/src/Session/SALOME_Session_QThread.hxx index 9e9941bd7..a61f5dc72 100644 --- a/src/Session/SALOME_Session_QThread.hxx +++ b/src/Session/SALOME_Session_QThread.hxx @@ -41,7 +41,7 @@ class SALOME_Session_QThread: public QThread { public: - SALOME_Session_QThread(int argc, char ** argv) ; + SALOME_Session_QThread(int argc, char ** argv, QMutex *theGUIMutex) ; //! launch the Qt main window of the GUI on a separate thread virtual void run() ; @@ -55,6 +55,7 @@ protected: int _ret ; SALOME_NamingService *_NS; QApplication *_qappl ; + QMutex *_GUIMutex; SALOMEGUI_Application* _mw ; } ; diff --git a/src/Session/SALOME_Session_i.cxx b/src/Session/SALOME_Session_i.cxx index 026584560..a55bf4d46 100644 --- a/src/Session/SALOME_Session_i.cxx +++ b/src/Session/SALOME_Session_i.cxx @@ -52,7 +52,7 @@ SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, P { _argc = argc ; _argv = argv ; - _IAPPThread = new SALOME_Session_QThread(_argc, _argv) ; + _IAPPThread = new SALOME_Session_QThread(_argc, _argv, &_GUIMutex) ; _isGUI = FALSE ; _runningStudies= 0 ; _orb = CORBA::ORB::_duplicate(orb) ; -- 2.39.2