changeset 1456:68827c07e683

fix recursive calls with Lua
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 02 Jul 2015 15:44:24 +0200
parents a68545767975
children 6a9daad345c1
files OrthancServer/LuaScripting.cpp OrthancServer/LuaScripting.h OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h
diffstat 4 files changed, 14 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/LuaScripting.cpp	Thu Jul 02 15:17:19 2015 +0200
+++ b/OrthancServer/LuaScripting.cpp	Thu Jul 02 15:44:24 2015 +0200
@@ -390,7 +390,7 @@
                                           DicomInstanceToStore& instance,
                                           const Json::Value& simplifiedTags)
   {
-    boost::mutex::scoped_lock lock(mutex_);
+    boost::recursive_mutex::scoped_lock lock(mutex_);
 
     Json::Value metadata = Json::objectValue;
 
@@ -437,7 +437,7 @@
     if (context_.GetIndex().LookupResource(tags, change.GetPublicId(), change.GetResourceType()) &&
         context_.GetIndex().GetMetadata(metadata, change.GetPublicId()))
     {
-      boost::mutex::scoped_lock lock(mutex_);
+      boost::recursive_mutex::scoped_lock lock(mutex_);
 
       if (lua_.IsExistingFunction(name))
       {
@@ -472,7 +472,7 @@
   {
     static const char* NAME = "ReceivedInstanceFilter";
 
-    boost::mutex::scoped_lock lock(mutex_);
+    boost::recursive_mutex::scoped_lock lock(mutex_);
 
     if (lua_.IsExistingFunction(NAME))
     {
--- a/OrthancServer/LuaScripting.h	Thu Jul 02 15:17:19 2015 +0200
+++ b/OrthancServer/LuaScripting.h	Thu Jul 02 15:44:24 2015 +0200
@@ -67,7 +67,7 @@
 
     void OnStableResource(const ServerIndexChange& change);
 
-    boost::mutex    mutex_;
+    boost::recursive_mutex    mutex_;
     LuaContext      lua_;
     ServerContext&  context_;
 
@@ -76,16 +76,13 @@
     {
     private:
       LuaScripting& that_;
+      boost::recursive_mutex::scoped_lock lock_;
 
     public:
-      Locker(LuaScripting& that) : that_(that)
+      Locker(LuaScripting& that) : 
+        that_(that), 
+        lock_(that.mutex_)
       {
-        that.mutex_.lock();
-      }
-
-      ~Locker()
-      {
-        that_.mutex_.unlock();
       }
 
       LuaContext& GetLua()
--- a/OrthancServer/ServerContext.cpp	Thu Jul 02 15:17:19 2015 +0200
+++ b/OrthancServer/ServerContext.cpp	Thu Jul 02 15:44:24 2015 +0200
@@ -77,7 +77,7 @@
       {
         const ServerIndexChange& change = dynamic_cast<const ServerIndexChange&>(*obj.get());
 
-        boost::mutex::scoped_lock lock(that->listenersMutex_);
+        boost::recursive_mutex::scoped_lock lock(that->listenersMutex_);
         for (ServerListeners::iterator it = that->listeners_.begin(); 
              it != that->listeners_.end(); ++it)
         {
@@ -180,7 +180,7 @@
       bool accepted = true;
 
       {
-        boost::mutex::scoped_lock lock(listenersMutex_);
+        boost::recursive_mutex::scoped_lock lock(listenersMutex_);
 
         for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
         {
@@ -266,7 +266,7 @@
       if (status == StoreStatus_Success ||
           status == StoreStatus_AlreadyStored)
       {
-        boost::mutex::scoped_lock lock(listenersMutex_);
+        boost::recursive_mutex::scoped_lock lock(listenersMutex_);
 
         for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
         {
@@ -439,7 +439,7 @@
     plugins_ = &plugins;
 
     // TODO REFACTOR THIS
-    boost::mutex::scoped_lock lock(listenersMutex_);
+    boost::recursive_mutex::scoped_lock lock(listenersMutex_);
     listeners_.clear();
     listeners_.push_back(ServerListener(lua_, "Lua"));
     listeners_.push_back(ServerListener(plugins, "plugin"));
@@ -451,7 +451,7 @@
     plugins_ = NULL;
 
     // TODO REFACTOR THIS
-    boost::mutex::scoped_lock lock(listenersMutex_);
+    boost::recursive_mutex::scoped_lock lock(listenersMutex_);
     listeners_.clear();
     listeners_.push_back(ServerListener(lua_, "Lua"));
   }
--- a/OrthancServer/ServerContext.h	Thu Jul 02 15:17:19 2015 +0200
+++ b/OrthancServer/ServerContext.h	Thu Jul 02 15:44:24 2015 +0200
@@ -120,7 +120,7 @@
     LuaScripting lua_;
     OrthancPlugins* plugins_;
     ServerListeners listeners_;
-    boost::mutex listenersMutex_;
+    boost::recursive_mutex listenersMutex_;
 
     bool done_;
     SharedMessageQueue  pendingChanges_;