changeset 7113:2f62c814aee2

making MetricsRegistry compatible with wasm
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Aug 2026 11:06:16 +0200
parents c155dfa1de8e
children d850970fb101
files OrthancFramework/Sources/MetricsRegistry.cpp OrthancFramework/Sources/MetricsRegistry.h
diffstat 2 files changed, 14 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/MetricsRegistry.cpp	Fri Aug 14 10:12:33 2026 +0200
+++ b/OrthancFramework/Sources/MetricsRegistry.cpp	Fri Aug 14 11:06:16 2026 +0200
@@ -403,7 +403,7 @@
 
   void MetricsRegistry::SetEnabled(bool enabled)
   {
-    boost::mutex::scoped_lock lock(mutex_);
+    Mutex::ScopedLock lock(mutex_);
     enabled_ = enabled;
   }
 
@@ -412,7 +412,7 @@
                                  MetricsUpdatePolicy policy,
                                  MetricsDataType type)
   {
-    boost::mutex::scoped_lock lock(mutex_);
+    Mutex::ScopedLock lock(mutex_);
 
     if (content_.find(name) != content_.end())
     {
@@ -472,7 +472,7 @@
     // Inlining to avoid loosing time if metrics are disabled
     if (enabled_)
     {
-      boost::mutex::scoped_lock lock(mutex_);
+      Mutex::ScopedLock lock(mutex_);
       GetItemInternal(name, policy, MetricsDataType_Float).UpdateFloat(value);
     }
   }
@@ -485,7 +485,7 @@
     // Inlining to avoid loosing time if metrics are disabled
     if (enabled_)
     {
-      boost::mutex::scoped_lock lock(mutex_);
+      Mutex::ScopedLock lock(mutex_);
       GetItemInternal(name, policy, MetricsDataType_Integer).UpdateInteger(value);
     }
   }
@@ -497,7 +497,7 @@
     // Inlining to avoid loosing time if metrics are disabled
     if (enabled_)
     {
-      boost::mutex::scoped_lock lock(mutex_);
+      Mutex::ScopedLock lock(mutex_);
       GetItemInternal(name, MetricsUpdatePolicy_Directly, MetricsDataType_Integer).IncrementInteger(delta);
     }
   }
@@ -507,7 +507,7 @@
   {
     if (enabled_)
     {
-      boost::mutex::scoped_lock lock(mutex_);
+      Mutex::ScopedLock lock(mutex_);
       GetItemInternal(name, MetricsUpdatePolicy_Directly, MetricsDataType_Integer).SetInitialValue(value);
     }
   }
@@ -515,7 +515,7 @@
 
   MetricsUpdatePolicy MetricsRegistry::GetUpdatePolicy(const std::string& metrics)
   {
-    boost::mutex::scoped_lock lock(mutex_);
+    Mutex::ScopedLock lock(mutex_);
 
     Content::const_iterator found = content_.find(metrics);
 
@@ -533,7 +533,7 @@
 
   MetricsDataType MetricsRegistry::GetDataType(const std::string& metrics)
   {
-    boost::mutex::scoped_lock lock(mutex_);
+    Mutex::ScopedLock lock(mutex_);
 
     Content::const_iterator found = content_.find(metrics);
 
@@ -554,7 +554,7 @@
     // https://www.boost.org/doc/libs/1_69_0/doc/html/date_time/examples.html#date_time.examples.seconds_since_epoch
     static const boost::posix_time::ptime EPOCH(boost::gregorian::date(1970, 1, 1));
 
-    boost::mutex::scoped_lock lock(mutex_);
+    Mutex::ScopedLock lock(mutex_);
 
     s.clear();
 
@@ -600,14 +600,14 @@
 
   void MetricsRegistry::SharedMetrics::Add(int64_t delta)
   {
-    boost::mutex::scoped_lock lock(mutex_);
+    Mutex::ScopedLock lock(mutex_);
     value_ += delta;
     registry_.SetIntegerValue(name_, value_);
   }
 
   void MetricsRegistry::SharedMetrics::SetInitialValue(int64_t value)
   {
-    boost::mutex::scoped_lock lock(mutex_);
+    Mutex::ScopedLock lock(mutex_);
     value_ = value;
     registry_.SetInitialValue(name_, value_);
   }
--- a/OrthancFramework/Sources/MetricsRegistry.h	Fri Aug 14 10:12:33 2026 +0200
+++ b/OrthancFramework/Sources/MetricsRegistry.h	Fri Aug 14 11:06:16 2026 +0200
@@ -30,12 +30,9 @@
 #  error The macro ORTHANC_SANDBOXED must be defined
 #endif
 
-#if ORTHANC_SANDBOXED == 1
-#  error The class MetricsRegistry cannot be used in sandboxed environments
-#endif
+#include "MultiThreading/Mutex.h"
 
 #include <boost/noncopyable.hpp>
-#include <boost/thread/mutex.hpp>
 #include <map>
 #include <stdint.h>
 
@@ -67,7 +64,7 @@
     typedef std::map<std::string, Item*>   Content;
 
     bool          enabled_;
-    boost::mutex  mutex_;
+    Mutex         mutex_;
     Content       content_;
 
     // The mutex must be locked
@@ -125,7 +122,7 @@
     class ORTHANC_PUBLIC SharedMetrics : public boost::noncopyable
     {
     private:
-      boost::mutex      mutex_;
+      Mutex             mutex_;
       MetricsRegistry&  registry_;
       std::string       name_;
       int64_t           value_;