changeset 6793:4514943d9239

added mutex to DicomDataSource::Dicom
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 17 May 2026 19:00:37 +0200
parents 323f93009cc8
children 2ec15c5ef4bd
files OrthancFramework/UnitTestsSources/JobsTests.cpp
diffstat 1 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/UnitTestsSources/JobsTests.cpp	Sun May 17 18:54:12 2026 +0200
+++ b/OrthancFramework/UnitTestsSources/JobsTests.cpp	Sun May 17 19:00:37 2026 +0200
@@ -2064,10 +2064,10 @@
   }
 
 
-  // TODO - Add mutex and accessor
   class Dicom : public boost::noncopyable
   {
   private:
+    boost::mutex                       mutex_;
     boost::shared_ptr<IDynamicObject>  value_;
 
   public:
@@ -2080,10 +2080,29 @@
       }
     }
 
-    ParsedDicomFile& GetContent() const
+    /**
+     * Access to the DICOM value must be protected by a mutex, as it
+     * could be shared by multiple threads if caching is enabled in
+     * the DataSourceReader.
+     **/
+    class Lock : public boost::noncopyable
     {
-      return dynamic_cast<const Value&>(*value_).GetDicom();
-    }
+    private:
+      Dicom&                     that_;
+      boost::mutex::scoped_lock  lock_;
+
+    public:
+      explicit Lock(Dicom& that) :
+        that_(that),
+        lock_(that.mutex_)
+      {
+      }
+
+      ParsedDicomFile& GetContent() const
+      {
+        return dynamic_cast<const Value&>(*that_.value_).GetDicom();
+      }
+    };
   };
 
   static Dicom* ReadWhole(DataSourceReader& reader,