From f6f7fdf2822f0a96f1597d2b547d095332618630 Mon Sep 17 00:00:00 2001 From: prascle Date: Tue, 6 Apr 2004 14:05:34 +0000 Subject: [PATCH] PR: colocalisation prototype 3 --- src/Session/SALOME_Session_Server.cxx | 13 +++++++-- src/Session/Session_ServerLauncher.cxx | 35 +++++++++++------------- src/Session/Session_ServerLauncher.hxx | 12 ++++---- src/Session/Session_ServerThread.cxx | 38 +++----------------------- src/Session/Session_ServerThread.hxx | 14 ++++------ 5 files changed, 42 insertions(+), 70 deletions(-) diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index d72a954d5..a2397fc6b 100644 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -104,14 +104,21 @@ int main(int argc, char **argv) // CORBA Servant Launcher QMutex _GUIMutex ; + QWaitCondition _ServerLaunch; + _GUIMutex.lock(); // to block Launch server thread until wait(mutex) Session_ServerLauncher* myServerLauncher - = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex); - myServerLauncher->Init(); + = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch); + myServerLauncher->start(); + + MESSAGE("waiting wakeAll()"); + _ServerLaunch.wait(&_GUIMutex); // to be reseased by Launch server thread when ready: + // atomic operation lock - unlock on mutex + // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll() + // this thread wakes up, and lock mutex INFOS("Session activated, Launch IAPP..."); - _GUIMutex.lock(); int qappArgc = 1; QApplication *_qappl = new QApplication(qappArgc, argv ); INFOS("creation QApplication"); diff --git a/src/Session/Session_ServerLauncher.cxx b/src/Session/Session_ServerLauncher.cxx index 54d852aa6..54cf11cba 100644 --- a/src/Session/Session_ServerLauncher.cxx +++ b/src/Session/Session_ServerLauncher.cxx @@ -52,13 +52,15 @@ Session_ServerLauncher::Session_ServerLauncher(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, - QMutex *GUIMutex) + QMutex *GUIMutex, + QWaitCondition *ServerLaunch) { _argc = argc; _argv = argv; _orb = CORBA::ORB::_duplicate(orb); _root_poa = PortableServer::POA::_duplicate(poa); _GUIMutex = GUIMutex; + _ServerLaunch = ServerLaunch; } //============================================================================= @@ -77,10 +79,18 @@ Session_ServerLauncher::~Session_ServerLauncher() */ //============================================================================= -void Session_ServerLauncher::Init() +void Session_ServerLauncher::run() { + MESSAGE("Session_ServerLauncher::run"); + _GUIMutex->lock(); // lock released by calling thread when ready: wait(mutex) + MESSAGE("Server Launcher thread free to go..."); + _GUIMutex->unlock(); + CheckArgs(); ActivateAll(); + + _ServerLaunch->wakeAll(); + _orb->run(); // this thread wait, during omniORB process events } //============================================================================= @@ -171,8 +181,6 @@ void Session_ServerLauncher::CheckArgs() void Session_ServerLauncher::ActivateAll() { - _GUIMutex->lock(); // to block server threads until wait(mutex) - list::iterator itServ; for (itServ = _argServToLaunch.begin(); itServ !=_argServToLaunch.end(); itServ++) { @@ -188,15 +196,10 @@ void Session_ServerLauncher::ActivateAll() argv[i+1] = _argv[(*itServ)._firstArg + i]; } Session_ServerThread* aServerThread - = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex,&_ServerLaunch); + = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex); _serverThreads.push_back(aServerThread); - aServerThread->start(); - MESSAGE("waiting wakeAll()"); - _ServerLaunch.wait(_GUIMutex); // to be reseased by serverThread when ready: - // atomic operation lock - unlock on mutex - // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll() - // this thread wakes up, and lock mutex + aServerThread->Init(); } // Always launch Session Server @@ -205,15 +208,9 @@ void Session_ServerLauncher::ActivateAll() char** argv = new char*[argc]; argv[0] = "Session"; Session_ServerThread* aServerThread - = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex,&_ServerLaunch); + = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex); _serverThreads.push_back(aServerThread); - aServerThread->start(); - _ServerLaunch.wait(_GUIMutex); // to be reseased by serverThread when ready - // atomic operation lock - unlock on mutex - // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll() - // this thread wakes up, and lock mutex - - _GUIMutex->unlock(); // release mutex for Qt main Thread + aServerThread->Init(); } diff --git a/src/Session/Session_ServerLauncher.hxx b/src/Session/Session_ServerLauncher.hxx index 186a2f616..893754ac0 100644 --- a/src/Session/Session_ServerLauncher.hxx +++ b/src/Session/Session_ServerLauncher.hxx @@ -35,6 +35,7 @@ #include #include #include +#include #include using namespace std; @@ -52,7 +53,7 @@ inline ServArg::ServArg(int servType, int firstArg, int lastArg): _servType(servType),_firstArg(firstArg),_lastArg(lastArg) {} -class Session_ServerLauncher +class Session_ServerLauncher: public QThread { public: Session_ServerLauncher(); @@ -60,9 +61,10 @@ public: char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, - QMutex *GUIMutex); - virtual ~Session_ServerLauncher();; - void Init(); + QMutex *GUIMutex, + QWaitCondition *ServerLaunch); + virtual ~Session_ServerLauncher(); + void run(); protected: void CheckArgs(); @@ -76,7 +78,7 @@ private: CORBA::ORB_var _orb; PortableServer::POA_var _root_poa; QMutex* _GUIMutex; - QWaitCondition _ServerLaunch; + QWaitCondition *_ServerLaunch; list _argServToLaunch; vector _argCopy; list _serverThreads; diff --git a/src/Session/Session_ServerThread.cxx b/src/Session/Session_ServerThread.cxx index 6783d4a29..1cf8ca856 100644 --- a/src/Session/Session_ServerThread.cxx +++ b/src/Session/Session_ServerThread.cxx @@ -135,8 +135,7 @@ Session_ServerThread::Session_ServerThread(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, - QMutex *GUIMutex, - QWaitCondition *ServerLaunch) + QMutex *GUIMutex) { MESSAGE("Session_ServerThread Constructor " << argv[0]); _argc = argc; @@ -144,7 +143,6 @@ Session_ServerThread::Session_ServerThread(int argc, _orb = CORBA::ORB::_duplicate(orb); _root_poa = PortableServer::POA::_duplicate(poa); _GUIMutex = GUIMutex; - _ServerLaunch = ServerLaunch; _servType =-1; _NS = new SALOME_NamingService(_orb); // one instance per server to limit // multi thread coherence problems @@ -168,13 +166,9 @@ Session_ServerThread::~Session_ServerThread() */ //============================================================================= -void Session_ServerThread::run() +void Session_ServerThread::Init() { - MESSAGE("Session_ServerThread::run "<< _argv[0]); - - _GUIMutex->lock(); // lock released by calling thread when ready: wait(mutex) - MESSAGE("Server thread " << _argv[0] << " free to go..."); - _GUIMutex->unlock(); + MESSAGE("Session_ServerThread::Init "<< _argv[0]); for (int i=0; i<_argc; i++) SCRUTE(_argv[i]); for (int i=0; iRegister(myCata ,"/Kernel/ModulCatalog"); MESSAGE("---"); - _ServerLaunch->wakeAll(); - _orb->run(); // this thread wait, during process events } catch(CORBA::SystemException&) { @@ -303,9 +295,6 @@ void Session_ServerThread::ActivateSALOMEDS(int argc, = _root_poa->activate_object(myStudyManager_i); myStudyManager_i->register_name("/myStudyManager"); - - _ServerLaunch->wakeAll(); - _orb->run(); // this thread wait, during process events } catch(CORBA::SystemException&) { @@ -382,16 +371,6 @@ void Session_ServerThread::ActivateRegistry(int argc, string absoluteName = string("/") + registryName; _NS->Register( varComponents , absoluteName.c_str() ); MESSAGE("On attend les requetes des clients"); - try - { - _ServerLaunch->wakeAll(); - _orb->run(); - } - catch( const CORBA::Exception &ex ) - { - INFOS("Erreur systeme"); - ASSERT(0); - } } catch( const SALOME_Exception &ex ) { @@ -473,9 +452,6 @@ void Session_ServerThread::ActivateContainer(int argc, Engines_Container_i * myContainer = new Engines_Container_i(_orb, factory_poa, containerName , argc , argv ); - MESSAGE("---"); - _ServerLaunch->wakeAll(); - _orb->run(); // this thread wait, during process events } catch(CORBA::SystemException&) { @@ -521,13 +497,7 @@ void Session_ServerThread::ActivateSession(int argc, CORBA::String_var sior(_orb->object_to_string(obj)); mySALOME_Session->NSregister(); - - mySALOME_Session->_remove_ref(); - - _ServerLaunch->wakeAll(); - MESSAGE("---"); - _orb->run() ; // this thread wait, during process events - } + } catch (CORBA::SystemException&) { INFOS("Caught CORBA::SystemException."); diff --git a/src/Session/Session_ServerThread.hxx b/src/Session/Session_ServerThread.hxx index 3c2249b0c..3c12b138e 100644 --- a/src/Session/Session_ServerThread.hxx +++ b/src/Session/Session_ServerThread.hxx @@ -29,20 +29,18 @@ #ifndef _SESSION_SERVERTHREAD_HXX_ #define _SESSION_SERVERTHREAD_HXX_ -#include #include +#include #include "SALOME_NamingService.hxx" - -#include -#include +#include using namespace std; void WaitForServerReadiness(string serverName); -class Session_ServerThread: public QThread +class Session_ServerThread { public: static const int NB_SRV_TYP; @@ -53,10 +51,9 @@ public: char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, - QMutex *GUIMutex, - QWaitCondition *ServerLaunch); + QMutex *GUIMutex); virtual ~Session_ServerThread(); - void run(); + void Init(); protected: void ActivateModuleCatalog(int argc, char ** argv); @@ -76,7 +73,6 @@ private: CORBA::ORB_var _orb; PortableServer::POA_var _root_poa; QMutex* _GUIMutex; - QWaitCondition *_ServerLaunch; SALOME_NamingService *_NS; }; -- 2.39.2