]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
DSM in multithread mode.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Thu, 30 Sep 2021 12:37:01 +0000 (14:37 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 30 Sep 2021 15:36:15 +0000 (17:36 +0200)
src/SALOMESDS/SALOMESDS_DataServerManager.cxx
src/SALOMESDS/SALOMESDS_DataServerManager.hxx
src/SALOMESDS/SALOMESDS_RequestSwitcher.hxx
src/SALOMESDS/TestSalomeSDS.py

index 80ba9319e67bffda9931258806a3344e9971e540..57da8196336ba36a19b7718193ebf8514acf632a 100644 (file)
@@ -37,14 +37,25 @@ const char DataServerManager::DFT_SCOPE_NAME_IN_NS[]="Default";
 
 SALOME::StringVec *RequestSwitcherDSM::listScopes()
 {
-  return _dsm->listScopes();
+  return _dsm->listScopes_unsafe();
 }
 
 SALOME::DataScopeServerTransaction_ptr RequestSwitcherDSM::giveADataScopeTransactionCalled(const char *scopeName, CORBA::Boolean& isCreated)
 {
-  return _dsm->giveADataScopeTransactionCalled(scopeName,isCreated);
+  return _dsm->giveADataScopeTransactionCalled_unsafe(scopeName,isCreated);
 }
 
+void RequestSwitcherDSM::holdRequests()
+{
+  _dsm->holdRequests();
+}
+
+void RequestSwitcherDSM::activeRequests()
+{
+  _dsm->activeRequests();
+}
+
+
 DataServerManager::DataServerManager(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, SALOME_NamingService_Abstract *ns):_orb(CORBA::ORB::_duplicate(orb))
 {
   _ns = ns==nullptr?new SALOME_NamingService(_orb):ns;
@@ -54,7 +65,8 @@ DataServerManager::DataServerManager(const SALOME_CPythonHelper *pyHelper, CORBA
   policies.length(1);
   PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
   policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol);
-  _poa=poa->create_POA("SingleThPOA4SDS",pman,policies);
+  PortableServer::POA_var safePoa = poa->create_POA("SingleThPOA4SDS",pman,policies);
+  _poa = poa;
   threadPol->destroy();
   // activate this to be ready to be usable from NS.
   PortableServer::ObjectId_var id(_poa->activate_object(this));
@@ -75,7 +87,7 @@ DataServerManager::~DataServerManager()
   delete _ns;
 }
 
-SALOME::StringVec *DataServerManager::listScopes()
+SALOME::StringVec * DataServerManager::listScopes_unsafe()
 {
   std::vector<std::string> scopes(listOfScopesCpp());
   SALOME::StringVec *ret(new SALOME::StringVec);
@@ -86,14 +98,21 @@ SALOME::StringVec *DataServerManager::listScopes()
   return ret;
 }
 
+SALOME::StringVec *DataServerManager::listScopes()
+{
+  const std::lock_guard<std::mutex> lock(_mutex);
+  return listScopes_unsafe();
+}
+
 SALOME::StringVec *DataServerManager::listAliveAndKickingScopes()
 {
+  const std::lock_guard<std::mutex> lock(_mutex);
   std::vector<std::string> scopes(listOfScopesCpp());
   std::size_t sz(scopes.size());
   std::vector<std::string> retCpp; retCpp.reserve(sz);
   for(std::size_t i=0;i<sz;i++)
     {
-      if(isAliveAndKicking(scopes[i].c_str()))
+      if(isAliveAndKicking_unsafe(scopes[i].c_str()))
         retCpp.push_back(scopes[i]);
     }
   //
@@ -107,7 +126,8 @@ SALOME::StringVec *DataServerManager::listAliveAndKickingScopes()
 
 SALOME::DataScopeServer_ptr DataServerManager::getDefaultScope()
 {
-  SALOME::DataScopeServerBase_var ret(retriveDataScope(DFT_SCOPE_NAME_IN_NS));
+  const std::lock_guard<std::mutex> lock(_mutex);
+  SALOME::DataScopeServerBase_var ret(retriveDataScope_unsafe(DFT_SCOPE_NAME_IN_NS));
   if(CORBA::is_nil(ret))
     return SALOME::DataScopeServer::_narrow(ret);
   SALOME::DataScopeServer_ptr ret2(SALOME::DataScopeServer::_narrow(ret));
@@ -117,6 +137,12 @@ SALOME::DataScopeServer_ptr DataServerManager::getDefaultScope()
 }
 
 CORBA::Boolean DataServerManager::isAliveAndKicking(const char *scopeName)
+{
+  const std::lock_guard<std::mutex> lock(_mutex);
+  return isAliveAndKicking_unsafe(scopeName);
+}
+
+CORBA::Boolean DataServerManager::isAliveAndKicking_unsafe(const char *scopeName)
 {
   SALOME::DataScopeServerBase_var scopePtr(getScopePtrGivenName(scopeName));
   return IsAliveAndKicking(scopePtr);
@@ -226,25 +252,43 @@ public:
 
 SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scopeName)
 {
+  const std::lock_guard<std::mutex> lock(_mutex);
   return CreateDataScope<NormalFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns);
 }
 
 SALOME::DataScopeServer_ptr DataServerManager::giveADataScopeCalled(const char *scopeName, CORBA::Boolean& isCreated)
 {
+  const std::lock_guard<std::mutex> lock(_mutex);
   return GiveADataScopeCalled<NormalFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns,isCreated);
 }
 
 SALOME::DataScopeServerTransaction_ptr DataServerManager::createDataScopeTransaction(const char *scopeName)
 {
+  const std::lock_guard<std::mutex> lock(_mutex);
   return CreateDataScope<TransactionFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns);
 }
 
-SALOME::DataScopeServerTransaction_ptr DataServerManager::giveADataScopeTransactionCalled(const char *scopeName, CORBA::Boolean& isCreated)
+SALOME::DataScopeServerTransaction_ptr
+DataServerManager::giveADataScopeTransactionCalled_unsafe(
+                              const char *scopeName, CORBA::Boolean& isCreated)
 {
   return GiveADataScopeCalled<TransactionFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns,isCreated);
 }
 
+
+SALOME::DataScopeServerTransaction_ptr DataServerManager::giveADataScopeTransactionCalled(const char *scopeName, CORBA::Boolean& isCreated)
+{
+  const std::lock_guard<std::mutex> lock(_mutex);
+  return giveADataScopeTransactionCalled_unsafe(scopeName, isCreated);
+}
+
 SALOME::DataScopeServerBase_ptr DataServerManager::retriveDataScope(const char *scopeName)
+{
+  const std::lock_guard<std::mutex> lock(_mutex);
+  return retriveDataScope_unsafe(scopeName);
+}
+
+SALOME::DataScopeServerBase_ptr DataServerManager::retriveDataScope_unsafe(const char *scopeName)
 {
   SALOME::DataScopeServerBase_var ret(getScopePtrGivenName(scopeName));
   return SALOME::DataScopeServerBase::_duplicate(ret);
@@ -252,6 +296,7 @@ SALOME::DataScopeServerBase_ptr DataServerManager::retriveDataScope(const char *
 
 void DataServerManager::removeDataScope(const char *scopeName)
 {
+  const std::lock_guard<std::mutex> lock(_mutex);
   SALOME::DataScopeServerBase_var scs(getScopePtrGivenName(scopeName));
   SALOME::DataScopeKiller_ptr killer;
   if(scs->shutdownIfNotHostedByDSM(killer))
@@ -261,10 +306,11 @@ void DataServerManager::removeDataScope(const char *scopeName)
 
 void DataServerManager::cleanScopesInNS()
 {
+  const std::lock_guard<std::mutex> lock(_mutex);
   std::vector<std::string> scopes(listOfScopesCpp());
   for(std::vector<std::string>::const_iterator it=scopes.begin();it!=scopes.end();it++)
     {
-      if(!isAliveAndKicking((*it).c_str()))
+      if(!isAliveAndKicking_unsafe((*it).c_str()))
         {
           std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(*it));
           _ns->Destroy_Name(fullScopeName.c_str());
@@ -274,6 +320,7 @@ void DataServerManager::cleanScopesInNS()
 
 void DataServerManager::shutdownScopes()
 {
+  const std::lock_guard<std::mutex> lock(_mutex);
   std::vector<std::string> scopeNames(listOfScopesCpp());
   for(std::vector<std::string>::const_iterator it=scopeNames.begin();it!=scopeNames.end();it++)
     {
@@ -330,6 +377,7 @@ SALOME::DataScopeServerBase_var DataServerManager::getScopePtrGivenName(const st
 
 SALOME::RequestSwitcherDSM_ptr DataServerManager::getRequestSwitcher()
 {
+  const std::lock_guard<std::mutex> lock(_mutex);
   if(_rs.isNull())
     {
       _rs=new RequestSwitcherDSM(_orb,this);
@@ -337,3 +385,13 @@ SALOME::RequestSwitcherDSM_ptr DataServerManager::getRequestSwitcher()
   CORBA::Object_var obj(_rs->activate());
   return SALOME::RequestSwitcherDSM::_narrow(obj);
 }
+
+void DataServerManager::holdRequests()
+{
+  _mutex.lock();
+}
+
+void DataServerManager::activeRequests()
+{
+  _mutex.unlock();
+}
index b7594e94478be007c25539fb68fe66b2731338a8..41c631fc24d5634de197d835a9d26658a1d9856b 100644 (file)
@@ -31,6 +31,7 @@
 #include "SALOMESDS_Defines.hxx"
 
 #include <string>
+#include <mutex>
 
 class SALOME_NamingService_Abstract;
 
@@ -44,6 +45,8 @@ namespace SALOMESDS
     RequestSwitcherDSM(CORBA::ORB_ptr orb, DataServerManager *dsm):RequestSwitcherBase(orb),_dsm(dsm) { }
     SALOME::StringVec *listScopes();
     SALOME::DataScopeServerTransaction_ptr giveADataScopeTransactionCalled(const char *scopeName, CORBA::Boolean& isCreated);
+    void holdRequests()override;
+    void activeRequests()override;
   private:
     DataServerManager *_dsm;
   };
@@ -71,17 +74,25 @@ namespace SALOMESDS
     void cleanScopesInNS();
     void shutdownScopes();
     SALOME::RequestSwitcherDSM_ptr getRequestSwitcher();
+    void holdRequests();
+    void activeRequests();
+
   public:
     CORBA::ORB_var getORB() { return _orb; }
     static std::string CreateAbsNameInNSFromScopeName(const std::string& scopeName);
     static CORBA::Boolean IsAliveAndKicking(SALOME::DataScopeServerBase_ptr scopePtr);
     static SALOME::DataScopeServerBase_var GetScopePtrGivenName(const std::string& scopeName, const std::vector<std::string>& scopes, SALOME_NamingService_Abstract *ns);
+    SALOME::StringVec *listScopes_unsafe();
+    SALOME::DataScopeServerTransaction_ptr giveADataScopeTransactionCalled_unsafe(
+                              const char *scopeName, CORBA::Boolean& isCreated);
   public:
     static const char NAME_IN_NS[];
     static const char DFT_SCOPE_NAME_IN_NS[];
   private:
     std::vector<std::string> listOfScopesCpp();
     SALOME::DataScopeServerBase_var getScopePtrGivenName(const std::string& scopeName);
+    CORBA::Boolean isAliveAndKicking_unsafe(const char *scopeName);
+    SALOME::DataScopeServerBase_ptr retriveDataScope_unsafe(const char *scopeName);
   private:
     //! naming service object is owned
     SALOME_NamingService_Abstract *_ns = nullptr;
@@ -89,6 +100,7 @@ namespace SALOMESDS
     //! single thread poa
     PortableServer::POA_var _poa;
     AutoServantPtr<RequestSwitcherDSM> _rs;
+    std::mutex _mutex;
   };
 }
 
index 83e724fc40cb9cbc3bf78c465cdcbb9d7b1473f4..8875e4cb3280d9e4c625b02e9c8c5a916ed4bffa 100644 (file)
@@ -36,8 +36,8 @@ namespace SALOMESDS
   {
   public:
     RequestSwitcherBase(CORBA::ORB_ptr orb);
-    void holdRequests();
-    void activeRequests();
+    virtual void holdRequests();
+    virtual void activeRequests();
     PortableServer::POA_var getPOA() const { return _poa_for_request_control; }
   private:
     PortableServer::POA_var _poa_for_request_control;
index 526b6d8049ff812b26dc1b7243e527058f98619e..2dc132dc12f3a70a2977ff3114dc9d7e05eeeaff 100644 (file)
@@ -494,6 +494,16 @@ class SalomeSDSTest(unittest.TestCase):
     dsm.removeDataScope(scopeName)
     pass
   
+  def testShutdownScopes(self):
+    """ Test shutdownScopes.
+    """
+    salome.salome_init()
+    dss, isCreated = salome.dsm.giveADataScopeTransactionCalled('scope0')
+    t0 = dss.createRdExtVarTransac('a', obj2Str({}))
+    dss.atomicApply([t0])
+    salome.dsm.shutdownScopes() # no exception expected
+    pass
+
   pass
 
 if __name__=="__main__":