diff OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp @ 4594:d494b4f1103e db-changes

removed the global database mutex from ServerIndex and StatelessDatabaseOperations
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 16 Mar 2021 12:43:43 +0100
parents 60a860942c5e
children cc64385593ef
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp	Mon Mar 15 18:22:53 2021 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp	Tue Mar 16 12:43:43 2021 +0100
@@ -60,10 +60,10 @@
     typedef std::pair<int64_t, ResourceType>     AnswerResource;
     typedef std::map<MetadataType, std::string>  AnswerMetadata;
 
-    OrthancPluginDatabase&  that_;
-    IDatabaseListener&      listener_;
-
-    _OrthancPluginDatabaseAnswerType type_;
+    OrthancPluginDatabase&               that_;
+    boost::recursive_mutex::scoped_lock  lock_;
+    IDatabaseListener&                   listener_;
+    _OrthancPluginDatabaseAnswerType     type_;
 
     std::list<std::string>         answerStrings_;
     std::list<int32_t>             answerInt32_;
@@ -228,6 +228,7 @@
     explicit Transaction(OrthancPluginDatabase& that,
                          IDatabaseListener& listener) :
       that_(that),
+      lock_(that.mutex_),
       listener_(listener),
       type_(_OrthancPluginDatabaseAnswerType_None),
       answerDoneIgnored_(false)
@@ -1508,7 +1509,10 @@
 
   void OrthancPluginDatabase::Open()
   {
-    CheckSuccess(backend_.open(payload_));
+    {
+      boost::recursive_mutex::scoped_lock lock(mutex_);
+      CheckSuccess(backend_.open(payload_));
+    }
 
     VoidDatabaseListener listener;
     
@@ -1537,6 +1541,13 @@
   }
 
 
+  void OrthancPluginDatabase::Close()
+  {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+    CheckSuccess(backend_.close(payload_));
+  }
+
+
   IDatabaseWrapper::ITransaction* OrthancPluginDatabase::StartTransaction(TransactionType type,
                                                                           IDatabaseListener& listener)
   {
@@ -1596,9 +1607,15 @@
 
   void OrthancPluginDatabase::AnswerReceived(const _OrthancPluginDatabaseAnswer& answer)
   {
+    boost::recursive_mutex::scoped_lock lock(mutex_);
+
     if (activeTransaction_ != NULL)
     {
       activeTransaction_->AnswerReceived(answer);
     }
+    else
+    {
+      LOG(WARNING) << "Received an answer from the database index plugin, but not transaction is active";
+    }
   }
 }