changeset 5454:099d45f49fe1 pg-transactions

merge default -> pg-transactions
author Alain Mazy <am@osimis.io>
date Wed, 06 Dec 2023 14:20:33 +0100
parents 9ffd6d18daf3 (current diff) b750777c36a2 (diff)
children 176bc05f85f4
files
diffstat 7 files changed, 40 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Dec 05 16:26:35 2023 +0100
+++ b/NEWS	Wed Dec 06 14:20:33 2023 +0100
@@ -65,6 +65,7 @@
 
 * Plugins are now allowed to modify/delete private metadata/attachments
   (i.e. whose identifiers are < 1024)
+* Added "OrthancPluginSetCurrentThreadName()" in the plugin SDK.
 
 
 Maintenance
--- a/OrthancFramework/Sources/Logging.cpp	Tue Dec 05 16:26:35 2023 +0100
+++ b/OrthancFramework/Sources/Logging.cpp	Wed Dec 06 14:20:33 2023 +0100
@@ -539,6 +539,7 @@
 static boost::mutex                             loggingStreamsMutex_;
 static Orthanc::Logging::NullStream             nullStream_;
 static OrthancPluginContext*                    pluginContext_ = NULL;
+static boost::recursive_mutex                   threadNamesMutex_;
 static std::map<boost::thread::id, std::string> threadNames_;
 static bool                                     enableThreadNames_ = true;
 
@@ -624,7 +625,8 @@
 
     void SetCurrentThreadNameInternal(const boost::thread::id& id, const std::string& name)
     {
-      // this method assumes that the loggingStreamsMutex is already locked
+      boost::recursive_mutex::scoped_lock lock(threadNamesMutex_);
+
       if (name.size() > 16)
       {
         throw OrthancException(ErrorCode_InternalError, std::string("Thread name can not exceed 16 characters: ") + name);
@@ -635,7 +637,7 @@
 
     void SetCurrentThreadName(const std::string& name)
     {
-      boost::mutex::scoped_lock lock(loggingStreamsMutex_);
+      boost::recursive_mutex::scoped_lock lock(threadNamesMutex_);
       SetCurrentThreadNameInternal(boost::this_thread::get_id(), name);
     }
 
@@ -649,9 +651,10 @@
 
     static std::string GetCurrentThreadName()
     {
-      // this method assumes that the loggingStreamsMutex is already locked
       boost::thread::id threadId = boost::this_thread::get_id();
 
+      boost::recursive_mutex::scoped_lock lock(threadNamesMutex_);
+
       if (threadNames_.find(threadId) == threadNames_.end())
       {
         // set the threadId as the thread name
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Tue Dec 05 16:26:35 2023 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Wed Dec 06 14:20:33 2023 +0100
@@ -5530,6 +5530,12 @@
         return true;
       }
 
+      case _OrthancPluginService_SetCurrentThreadName:
+      {
+        Logging::SetCurrentThreadName(std::string(reinterpret_cast<const char*>(parameters)));
+        return true;
+      }
+
       default:
         return false;
     }
--- a/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Tue Dec 05 16:26:35 2023 +0100
+++ b/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Wed Dec 06 14:20:33 2023 +0100
@@ -449,6 +449,8 @@
     _OrthancPluginService_CreateDicom2 = 41,         /* New in Orthanc 1.9.0 */
     _OrthancPluginService_GetDatabaseServerIdentifier = 42,         /* New in Orthanc 1.11.1 */
     _OrthancPluginService_SetMetricsIntegerValue = 43,              /* New in Orthanc 1.12.1 */
+    _OrthancPluginService_SetCurrentThreadName = 44,                /* New in Orthanc 1.12.2 */
+
 
     /* Registration of callbacks */
     _OrthancPluginService_RegisterRestCallback = 1000,
@@ -9356,6 +9358,25 @@
   }
 
 
+/**
+   * @brief Sets the name of the current thread
+   *
+   * This function sets the name of the thread that is calling it.
+   * This name is used in the logs.  This function shall be called only from threads that
+   * the plugin has created itself.
+   * 
+   * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
+   * @param threadName The name of the current thread.  A Thread name can not be larger than 16 characters.
+   * @return 0 if success, other value if error.
+   * @ingroup Toolbox
+   **/
+  ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetCurrentThreadName(
+    OrthancPluginContext*                        context,
+    const char*                                  threadName)
+  {
+    return context->InvokeService(context, _OrthancPluginService_SetCurrentThreadName, threadName);
+  }
+
 #ifdef  __cplusplus
 }
 #endif
--- a/OrthancServer/Plugins/Samples/DelayedDeletion/Plugin.cpp	Tue Dec 05 16:26:35 2023 +0100
+++ b/OrthancServer/Plugins/Samples/DelayedDeletion/Plugin.cpp	Wed Dec 06 14:20:33 2023 +0100
@@ -186,6 +186,8 @@
 
 static void DeletionWorker()
 {
+  OrthancPluginSetCurrentThreadName(OrthancPlugins::GetGlobalContext(), "DELETION");
+
   static const unsigned int GRANULARITY = 100;  // In milliseconds
 
   while (continue_)
--- a/OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp	Tue Dec 05 16:26:35 2023 +0100
+++ b/OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp	Wed Dec 06 14:20:33 2023 +0100
@@ -599,6 +599,8 @@
 
 static void WorkerThread()
 {
+  OrthancPluginSetCurrentThreadName(OrthancPlugins::GetGlobalContext(), "HOUSEKEEPER");
+
   DbConfiguration currentDbConfiguration;
 
   OrthancPluginLogWarning(OrthancPlugins::GetGlobalContext(), "Starting Housekeeper worker thread");
--- a/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp	Tue Dec 05 16:26:35 2023 +0100
+++ b/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp	Wed Dec 06 14:20:33 2023 +0100
@@ -243,8 +243,9 @@
 
   void ThreadedSetOfInstancesJob::InstanceWorkerThread(ThreadedSetOfInstancesJob* that)
   {
-    static uint8_t threadCounter = 0;
+    static uint16_t threadCounter = 0;
     Logging::SetCurrentThreadName(std::string("JOB-INS-WORK-") + boost::lexical_cast<std::string>(threadCounter++));
+    threadCounter %= 1000;
 
     while (true)
     {