changeset 7116:cf85d06bda8a

cont ORTHANC_ENABLE_THREADS
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Aug 2026 11:37:29 +0200
parents ae6345f0884d
children fc06d1b317c3
files OrthancFramework/Sources/Cache/MemoryObjectCache.h OrthancFramework/Sources/DataSource/DataSourceAnswer.h OrthancFramework/Sources/DataSource/DataSourceMemoryBudget.h OrthancFramework/Sources/DicomFormat/DicomMap.cpp OrthancFramework/Sources/MultiThreading/ReaderWriterLock.h
diffstat 5 files changed, 53 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/Cache/MemoryObjectCache.h	Fri Aug 14 11:22:37 2026 +0200
+++ b/OrthancFramework/Sources/Cache/MemoryObjectCache.h	Fri Aug 14 11:37:29 2026 +0200
@@ -25,10 +25,15 @@
 #pragma once
 
 #include "../OrthancFramework.h"
+
+#if !defined(ORTHANC_ENABLE_THREADS)
+#  error The macro ORTHANC_ENABLE_THREADS must be defined
+#endif
+
 #include "ICacheable.h"
 #include "LeastRecentlyUsedIndex.h"
 
-#if !defined(__EMSCRIPTEN__)
+#if ORTHANC_ENABLE_THREADS == 1
 // Multithreading is not supported in WebAssembly
 #  include <boost/thread/mutex.hpp>
 #  include <boost/thread/shared_mutex.hpp>
@@ -47,7 +52,7 @@
   private:
     class Item;
 
-#if !defined(__EMSCRIPTEN__)
+#if ORTHANC_ENABLE_THREADS == 1
     typedef boost::unique_lock<boost::shared_mutex> WriterLock;
     typedef boost::shared_lock<boost::shared_mutex> ReaderLock;
 
@@ -85,7 +90,7 @@
     class ORTHANC_PUBLIC Accessor : public boost::noncopyable
     {
     private:
-#if !defined(__EMSCRIPTEN__)
+#if ORTHANC_ENABLE_THREADS == 1
       ReaderLock                 readerLock_;
       WriterLock                 writerLock_;
       boost::mutex::scoped_lock  cacheLock_;
--- a/OrthancFramework/Sources/DataSource/DataSourceAnswer.h	Fri Aug 14 11:22:37 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceAnswer.h	Fri Aug 14 11:37:29 2026 +0200
@@ -24,8 +24,14 @@
 
 #pragma once
 
-#if defined(__EMSCRIPTEN__)
-#  error This file is currently not available if targeting WebAssembly
+#include "../OrthancFramework.h"
+
+#if !defined(ORTHANC_ENABLE_THREADS)
+#  error The macro ORTHANC_ENABLE_THREADS must be defined
+#endif
+
+#if ORTHANC_ENABLE_THREADS != 1
+#  error This file is currently not available without support for threads
 #endif
 
 #include "../Compatibility.h"
--- a/OrthancFramework/Sources/DataSource/DataSourceMemoryBudget.h	Fri Aug 14 11:22:37 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceMemoryBudget.h	Fri Aug 14 11:37:29 2026 +0200
@@ -24,12 +24,17 @@
 
 #pragma once
 
-#if defined(__EMSCRIPTEN__)
-#  error This file is currently not available if targeting WebAssembly
+#include "../OrthancFramework.h"
+
+#if !defined(ORTHANC_ENABLE_THREADS)
+#  error The macro ORTHANC_ENABLE_THREADS must be defined
+#endif
+
+#if ORTHANC_ENABLE_THREADS != 1
+#  error This file is currently not available without support for threads
 #endif
 
 #include "../Compatibility.h"
-#include "../OrthancFramework.h"
 
 #include <boost/noncopyable.hpp>
 #include <boost/thread/condition_variable.hpp>
--- a/OrthancFramework/Sources/DicomFormat/DicomMap.cpp	Fri Aug 14 11:22:37 2026 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomMap.cpp	Fri Aug 14 11:37:29 2026 +0200
@@ -32,19 +32,14 @@
 
 #include "../Compatibility.h"
 #include "../Endianness.h"
+#include "../MultiThreading/ReaderWriterLock.h"
 #include "../OrthancException.h"
 #include "../Toolbox.h"
 #include "DicomArray.h"
 #include "DicomImageInformation.h"
 
 #if ORTHANC_ENABLE_DCMTK == 1
-#include "../DicomParsing/FromDcmtkBridge.h"
-#endif
-
-#if !defined(__EMSCRIPTEN__)
-// Multithreading is not supported in WebAssembly
-#  include <boost/thread/shared_mutex.hpp>
-#  include <boost/thread/lock_types.hpp>  // For boost::unique_lock<> and boost::shared_lock<>
+#  include "../DicomParsing/FromDcmtkBridge.h"
 #endif
 
 namespace Orthanc
@@ -152,13 +147,7 @@
   class DicomMap::MainDicomTagsConfiguration : public boost::noncopyable
   {
   private:
-#if !defined(__EMSCRIPTEN__)
-    typedef boost::unique_lock<boost::shared_mutex> WriterLock;
-    typedef boost::shared_lock<boost::shared_mutex> ReaderLock;
-
-    boost::shared_mutex mutex_;
-#endif
-    
+    ReaderWriterLock   mutex_;
     std::set<DicomTag> patientsMainDicomTagsByLevel_;
     std::set<DicomTag> studiesMainDicomTagsByLevel_;
     std::set<DicomTag> seriesMainDicomTagsByLevel_;
@@ -285,9 +274,7 @@
 
     void ResetDefaultMainDicomTags()
     {
-#if !defined(__EMSCRIPTEN__)
-      WriterLock lock(mutex_);
-#endif
+      ReaderWriterLock::WriteLock lock(mutex_);
       
       patientsMainDicomTagsByLevel_.clear();
       studiesMainDicomTagsByLevel_.clear();
@@ -322,68 +309,50 @@
     void AddMainDicomTag(const DicomTag& tag,
                          ResourceType level)
     {
-#if !defined(__EMSCRIPTEN__)
-      WriterLock lock(mutex_);
-#endif
+      ReaderWriterLock::WriteLock lock(mutex_);
       
       AddMainDicomTagInternal(tag, level);
     }
 
     void GetAllMainDicomTags(std::set<DicomTag>& target)
     {
-#if !defined(__EMSCRIPTEN__)
-      ReaderLock lock(mutex_);
-#endif
-      
+      ReaderWriterLock::ReadLock lock(mutex_);
       target = allMainDicomTags_;
     }
 
     void GetMainDicomTagsByLevel(std::set<DicomTag>& target,
                                  ResourceType level)
     {
-#if !defined(__EMSCRIPTEN__)
-      ReaderLock lock(mutex_);
-#endif
-      
+      ReaderWriterLock::ReadLock lock(mutex_);
       target = GetMainDicomTagsByLevelInternal(level);
     }
 
     std::string GetMainDicomTagsSignature(ResourceType level)
     {
-#if !defined(__EMSCRIPTEN__)
-      ReaderLock lock(mutex_);
-#endif
-      
+      ReaderWriterLock::ReadLock lock(mutex_);
       assert(signatures_.find(level) != signatures_.end());
       return signatures_[level];
     }
 
     std::string GetDefaultMainDicomTagsSignatureFrom1_11(ResourceType level)
     {
-#if !defined(__EMSCRIPTEN__)
-      ReaderLock lock(mutex_);
-#endif
-      
+      ReaderWriterLock::ReadLock lock(mutex_);
+
       assert(defaultSignatures_.find(level) != defaultSignatures_.end());
       return defaultSignatures_[level];
     }
 
     bool IsMainDicomTag(const DicomTag& tag)
     {
-#if !defined(__EMSCRIPTEN__)
-      ReaderLock lock(mutex_);
-#endif
-      
+      ReaderWriterLock::ReadLock lock(mutex_);
       return allMainDicomTags_.find(tag) != allMainDicomTags_.end();
     }
 
     bool IsMainDicomTag(const DicomTag& tag,
                         ResourceType level)
     {
-#if !defined(__EMSCRIPTEN__)
-      ReaderLock lock(mutex_);
-#endif
-      
+      ReaderWriterLock::ReadLock lock(mutex_);
+
       const std::set<DicomTag>& mainDicomTags = GetMainDicomTagsByLevelInternal(level);
       return mainDicomTags.find(tag) != mainDicomTags.end();
     }
--- a/OrthancFramework/Sources/MultiThreading/ReaderWriterLock.h	Fri Aug 14 11:22:37 2026 +0200
+++ b/OrthancFramework/Sources/MultiThreading/ReaderWriterLock.h	Fri Aug 14 11:37:29 2026 +0200
@@ -26,7 +26,17 @@
 
 #include "../OrthancFramework.h"
 
-#if !defined(__EMSCRIPTEN__)
+#if !defined(ORTHANC_ENABLE_THREADS)
+#  error The macro ORTHANC_ENABLE_THREADS must be defined
+#endif
+
+#if (ORTHANC_ENABLE_THREADS != 0) && (ORTHANC_ENABLE_THREADS != 1)
+#  error The macro ORTHANC_ENABLE_THREADS must set to 0 or 1
+#endif
+
+#include <boost/noncopyable.hpp>
+
+#if ORTHANC_ENABLE_THREADS == 1
 // Multithreading is not supported in WebAssembly
 #  include <boost/thread/shared_mutex.hpp>
 #  include <boost/thread/lock_types.hpp>  // For boost::unique_lock<> and boost::shared_lock<>
@@ -38,7 +48,7 @@
   class ORTHANC_PUBLIC ReaderWriterLock : public boost::noncopyable
   {
   private:
-#if !defined(__EMSCRIPTEN__)
+#if ORTHANC_ENABLE_THREADS == 1
     boost::shared_mutex mutex_;
 #endif
 
@@ -46,13 +56,13 @@
     class ReadLock : public boost::noncopyable
     {
     private:
-#if !defined(__EMSCRIPTEN__)
+#if ORTHANC_ENABLE_THREADS == 1
       boost::shared_lock<boost::shared_mutex> lock_;
 #endif
 
     public:
       explicit ReadLock(ReaderWriterLock& that)
-#if !defined(__EMSCRIPTEN__)
+#if ORTHANC_ENABLE_THREADS == 1
         : lock_(that.mutex_)
 #endif
       {
@@ -62,13 +72,13 @@
     class WriteLock : public boost::noncopyable
     {
     private:
-#if !defined(__EMSCRIPTEN__)
+#if ORTHANC_ENABLE_THREADS == 1
       boost::unique_lock<boost::shared_mutex> lock_;
 #endif
 
     public:
       explicit WriteLock(ReaderWriterLock& that)
-#if !defined(__EMSCRIPTEN__)
+#if ORTHANC_ENABLE_THREADS == 1
         : lock_(that.mutex_)
 #endif
       {