changeset 6529:e0979326ac53

merge
author Alain Mazy <am@orthanc.team>
date Tue, 02 Dec 2025 12:03:28 +0100
parents 5541a6b13500 (diff) 81f2cea4ab5f (current diff)
children c4cfb25a932b
files
diffstat 3 files changed, 27 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/Logging.cpp	Tue Dec 02 12:00:10 2025 +0100
+++ b/OrthancFramework/Sources/Logging.cpp	Tue Dec 02 12:03:28 2025 +0100
@@ -501,6 +501,7 @@
     _OrthancPluginService_LogInfo = 1,
     _OrthancPluginService_LogWarning = 2,
     _OrthancPluginService_LogError = 3,
+    _OrthancPluginService_SetCurrentThreadName = 44,
     _OrthancPluginService_LogMessage = 45,
     _OrthancPluginService_INTERNAL = 0x7fffffff
   } _OrthancPluginService;
@@ -671,15 +672,22 @@
 
     void SetCurrentThreadName(const std::string& name)
     {
-      boost::recursive_mutex::scoped_lock lock(threadNamesMutex_);
-      SetCurrentThreadNameInternal(boost::this_thread::get_id(), name);
+      if (pluginContext_ == NULL)
+      {
+        boost::recursive_mutex::scoped_lock lock(threadNamesMutex_);
+        SetCurrentThreadNameInternal(boost::this_thread::get_id(), name);
+      }
+      else
+      {
+        pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_SetCurrentThreadName, name.c_str());
+      }
     }
 
     bool HasCurrentThreadName()
     {
       boost::thread::id threadId = boost::this_thread::get_id();
 
-      boost::mutex::scoped_lock lock(loggingStreamsMutex_);
+      boost::recursive_mutex::scoped_lock lock(threadNamesMutex_);
       return threadNames_.find(threadId) != threadNames_.end();
     }
 
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Tue Dec 02 12:00:10 2025 +0100
+++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Tue Dec 02 12:03:28 2025 +0100
@@ -56,6 +56,8 @@
 static const char* const KEY_ARCHIVE_SIZE = "ArchiveSize";
 static const char* const KEY_TRANSCODE = "Transcode";
 
+static boost::mutex loaderThreadsCounterMutex;
+static uint32_t loaderThreadsCounter = 0;
 
 namespace Orthanc
 {
@@ -251,8 +253,11 @@
 
     static void PreloaderWorkerThread(ThreadedInstanceLoader* that)
     {
-      static uint16_t threadCounter = 0;
-      Logging::SetCurrentThreadName(std::string("ARCH-LOAD-") + boost::lexical_cast<std::string>(threadCounter++));
+      {
+        boost::mutex::scoped_lock lock(loaderThreadsCounterMutex);
+        Logging::SetCurrentThreadName(std::string("ARCH-LOAD-") + boost::lexical_cast<std::string>(loaderThreadsCounter++));
+        loaderThreadsCounter %= 1000000;
+      }
 
       LOG(INFO) << "Loader thread has started";
 
--- a/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp	Tue Dec 02 12:00:10 2025 +0100
+++ b/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp	Tue Dec 02 12:03:28 2025 +0100
@@ -31,6 +31,10 @@
 #include <boost/lexical_cast.hpp>
 #include <cassert>
 
+static boost::mutex instanceWorkerThreadsCounterMutex;
+static uint32_t instanceWorkerThreadsCounter = 0;
+
+
 namespace Orthanc
 {
   static const char* EXIT_WORKER_MESSAGE = "exit";
@@ -244,9 +248,11 @@
 
   void ThreadedSetOfInstancesJob::InstanceWorkerThread(ThreadedSetOfInstancesJob* that)
   {
-    static uint16_t threadCounter = 0;
-    Logging::SetCurrentThreadName(std::string("JOB-INS-WORK-") + boost::lexical_cast<std::string>(threadCounter++));
-    threadCounter %= 1000;
+    {
+      boost::mutex::scoped_lock lock(instanceWorkerThreadsCounterMutex);
+      Logging::SetCurrentThreadName(std::string("JOB-INS-WORK-") + boost::lexical_cast<std::string>(instanceWorkerThreadsCounter++));
+      instanceWorkerThreadsCounter %= 1000;
+    }
 
     while (true)
     {