changeset 4364:d527a081f92d

Allow concurrency on the OrthancPluginRegisterIncomingHttpRequestFilter() callbacks
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 Dec 2020 16:17:46 +0100
parents 1382c908d67c
children 3150306fb4ad
files NEWS OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h
diffstat 3 files changed, 27 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Dec 09 10:07:48 2020 +0100
+++ b/NEWS	Wed Dec 09 16:17:46 2020 +0100
@@ -11,6 +11,11 @@
 
 * "/instances" can be used to import ZIP archives provided in the POST body
 
+Maintenance
+-----------
+
+* Allow concurrency on the OrthancPluginRegisterIncomingHttpRequestFilter() callbacks
+
 
 Version 1.8.1 (2020-12-07)
 ==========================
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Wed Dec 09 10:07:48 2020 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Wed Dec 09 16:17:46 2020 +0100
@@ -930,6 +930,7 @@
     boost::mutex refreshMetricsMutex_;
     boost::mutex storageCommitmentScpMutex_;
     boost::recursive_mutex invokeServiceMutex_;
+    boost::shared_mutex incomingHttpRequestFilterMutex_;  // New in Orthanc 1.9.0
 
     Properties properties_;
     int argc_;
@@ -2155,6 +2156,8 @@
     const _OrthancPluginIncomingHttpRequestFilter& p = 
       *reinterpret_cast<const _OrthancPluginIncomingHttpRequestFilter*>(parameters);
 
+    boost::unique_lock<boost::shared_mutex> lock(pimpl_->incomingHttpRequestFilterMutex_);
+    
     CLOG(INFO, PLUGINS) << "Plugin has registered a callback to filter incoming HTTP requests";
     pimpl_->incomingHttpRequestFilters_.push_back(p.callback);
   }
@@ -2165,6 +2168,8 @@
     const _OrthancPluginIncomingHttpRequestFilter2& p = 
       *reinterpret_cast<const _OrthancPluginIncomingHttpRequestFilter2*>(parameters);
 
+    boost::unique_lock<boost::shared_mutex> lock(pimpl_->incomingHttpRequestFilterMutex_);
+    
     CLOG(INFO, PLUGINS) << "Plugin has registered a callback to filter incoming HTTP requests";
     pimpl_->incomingHttpRequestFilters2_.push_back(p.callback);
   }
@@ -4423,6 +4428,14 @@
         return true;
       }
         
+      case _OrthancPluginService_RegisterIncomingHttpRequestFilter:
+        RegisterIncomingHttpRequestFilter(parameters);
+        return true;
+
+      case _OrthancPluginService_RegisterIncomingHttpRequestFilter2:
+        RegisterIncomingHttpRequestFilter2(parameters);
+        return true;
+
       default:
         return false;
     }
@@ -4484,14 +4497,6 @@
         RegisterJobsUnserializer(parameters);
         return true;
 
-      case _OrthancPluginService_RegisterIncomingHttpRequestFilter:
-        RegisterIncomingHttpRequestFilter(parameters);
-        return true;
-
-      case _OrthancPluginService_RegisterIncomingHttpRequestFilter2:
-        RegisterIncomingHttpRequestFilter2(parameters);
-        return true;
-
       case _OrthancPluginService_RegisterIncomingDicomInstanceFilter:
         RegisterIncomingDicomInstanceFilter(parameters);
         return true;
@@ -4940,7 +4945,7 @@
     }
 
     {
-      boost::recursive_mutex::scoped_lock lock(pimpl_->invokeServiceMutex_);
+      boost::shared_lock<boost::shared_mutex> lock(pimpl_->incomingHttpRequestFilterMutex_);
     
       // Improved callback with support for GET arguments, since Orthanc 1.3.0
       for (PImpl::IncomingHttpRequestFilters2::const_iterator
--- a/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Wed Dec 09 10:07:48 2020 +0100
+++ b/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Wed Dec 09 16:17:46 2020 +0100
@@ -1267,6 +1267,10 @@
    * ("false"), the server answers with HTTP status code 403
    * (Forbidden).
    *
+   * Pay attention to the fact that this function may be invoked
+   * concurrently by different threads of the Web server of
+   * Orthanc. You must implement proper locking if applicable.
+   *
    * @param method The HTTP method used by the request.
    * @param uri The URI of interest.
    * @param ip The IP address of the HTTP client.
@@ -1296,6 +1300,10 @@
    * ("false"), the server answers with HTTP status code 403
    * (Forbidden).
    *
+   * Pay attention to the fact that this function may be invoked
+   * concurrently by different threads of the Web server of
+   * Orthanc. You must implement proper locking if applicable.
+   *
    * @param method The HTTP method used by the request.
    * @param uri The URI of interest.
    * @param ip The IP address of the HTTP client.