changeset 6527:ef77a536195b

fix SetCurrentThreadName from plugins
author Alain Mazy <am@orthanc.team>
date Tue, 02 Dec 2025 12:02:19 +0100
parents ebf563bfe42d
children 5541a6b13500
files OrthancFramework/Sources/Logging.cpp
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/Logging.cpp	Tue Dec 02 10:09:49 2025 +0100
+++ b/OrthancFramework/Sources/Logging.cpp	Tue Dec 02 12:02:19 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();
     }