changeset 1129:8dabdc0d3007

fix possible deadlock
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Sep 2014 15:47:53 +0200
parents 514492f61ead
children baac89e6cc4b
files OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h
diffstat 3 files changed, 4 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Mon Sep 08 15:22:21 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Mon Sep 08 15:47:53 2014 +0200
@@ -262,6 +262,7 @@
         continue;
       }
 
+
       ParsedDicomFile& original = locker->GetDicom();
       DicomInstanceHasher originalHasher = original.GetHasher();
 
--- a/OrthancServer/ServerContext.cpp	Mon Sep 08 15:22:21 2014 +0200
+++ b/OrthancServer/ServerContext.cpp	Mon Sep 08 15:47:53 2014 +0200
@@ -460,14 +460,14 @@
 
   ServerContext::DicomCacheLocker::DicomCacheLocker(ServerContext& that,
                                                     const std::string& instancePublicId) : 
-    that_(that)
+    that_(that),
+    lock_(that_.dicomCacheMutex_)
   {
 #if ENABLE_DICOM_CACHE == 0
     static std::auto_ptr<IDynamicObject> p;
     p.reset(provider_.Provide(instancePublicId));
     dicom_ = dynamic_cast<ParsedDicomFile*>(p.get());
 #else
-    that_.dicomCacheMutex_.lock();
     dicom_ = &dynamic_cast<ParsedDicomFile&>(that_.dicomCache_.Access(instancePublicId));
 #endif
   }
@@ -475,10 +475,6 @@
 
   ServerContext::DicomCacheLocker::~DicomCacheLocker()
   {
-#if ENABLE_DICOM_CACHE == 0
-#else
-    that_.dicomCacheMutex_.unlock();
-#endif
   }
 
 
--- a/OrthancServer/ServerContext.h	Mon Sep 08 15:22:21 2014 +0200
+++ b/OrthancServer/ServerContext.h	Mon Sep 08 15:47:53 2014 +0200
@@ -97,6 +97,7 @@
     private:
       ServerContext& that_;
       ParsedDicomFile *dicom_;
+      boost::mutex::scoped_lock lock_;
 
     public:
       DicomCacheLocker(ServerContext& that,