diff Plugins/Engine/OrthancPlugins.cpp @ 1466:0cd0f2ad3599

Fix potential deadlock in the callbacks of plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 28 Jul 2015 09:11:37 +0200
parents b737acb13da5
children f967bdf8534e
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp	Mon Jul 27 17:33:47 2015 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Tue Jul 28 09:11:37 2015 +0200
@@ -126,7 +126,9 @@
     OnChangeCallbacks  onChangeCallbacks_;
     bool hasStorageArea_;
     _OrthancPluginRegisterStorageArea storageArea_;
-    boost::recursive_mutex callbackMutex_;
+    boost::recursive_mutex restCallbackMutex_;
+    boost::recursive_mutex storedCallbackMutex_;
+    boost::recursive_mutex changeCallbackMutex_;
     Properties properties_;
     int argc_;
     char** argv_;
@@ -326,7 +328,7 @@
     int32_t error;
 
     {
-      boost::recursive_mutex::scoped_lock lock(pimpl_->callbackMutex_);
+      boost::recursive_mutex::scoped_lock lock(pimpl_->restCallbackMutex_);
       error = callback(reinterpret_cast<OrthancPluginRestOutput*>(&output), 
                        flatUri.c_str(), 
                        &request);
@@ -359,7 +361,7 @@
                                             DicomInstanceToStore& instance,
                                             const Json::Value& simplifiedTags)
   {
-    boost::recursive_mutex::scoped_lock lock(pimpl_->callbackMutex_);
+    boost::recursive_mutex::scoped_lock lock(pimpl_->storedCallbackMutex_);
 
     for (PImpl::OnStoredCallbacks::const_iterator
            callback = pimpl_->onStoredCallbacks_.begin(); 
@@ -376,7 +378,7 @@
   {
     try
     {
-      boost::recursive_mutex::scoped_lock lock(pimpl_->callbackMutex_);
+      boost::recursive_mutex::scoped_lock lock(pimpl_->changeCallbackMutex_);
 
       for (std::list<OrthancPluginOnChangeCallback>::const_iterator 
              callback = pimpl_->onChangeCallbacks_.begin();