changeset 2389:fc70ff98a5c7 refactoring

renamed RunnableThread as PeriodicRunnableThread
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 21 Oct 2026 14:40:48 +0200
parents 153403085188
children ba477e5a4981
files OrthancStone/Resources/CMake/OrthancStoneConfiguration.cmake OrthancStone/Sources/Platforms/Native/NativeEnvironment.h OrthancStone/Sources/Platforms/Native/PeriodicRunnableThread.cpp OrthancStone/Sources/Platforms/Native/PeriodicRunnableThread.h OrthancStone/Sources/Platforms/Native/RunnableThread.cpp OrthancStone/Sources/Platforms/Native/RunnableThread.h OrthancStone/Sources/Platforms/Native/ThreadedOracle.h
diffstat 7 files changed, 189 insertions(+), 189 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancStone/Resources/CMake/OrthancStoneConfiguration.cmake	Sun Oct 11 11:21:37 2026 +0200
+++ b/OrthancStone/Resources/CMake/OrthancStoneConfiguration.cmake	Wed Oct 21 14:40:48 2026 +0200
@@ -220,9 +220,9 @@
 if (NOT ORTHANC_SANDBOXED AND ENABLE_THREADS AND ENABLE_WEB_CLIENT)
   list(APPEND ORTHANC_STONE_SOURCES
     ${ORTHANC_STONE_ROOT}/Platforms/Native/GenericOracleRunner.cpp
+    ${ORTHANC_STONE_ROOT}/Platforms/Native/NativeEnvironment.cpp
+    ${ORTHANC_STONE_ROOT}/Platforms/Native/PeriodicRunnableThread.cpp
     ${ORTHANC_STONE_ROOT}/Platforms/Native/ThreadedOracle.cpp
-    ${ORTHANC_STONE_ROOT}/Platforms/Native/NativeEnvironment.cpp
-    ${ORTHANC_STONE_ROOT}/Platforms/Native/RunnableThread.cpp
     )
 endif()
 
--- a/OrthancStone/Sources/Platforms/Native/NativeEnvironment.h	Sun Oct 11 11:21:37 2026 +0200
+++ b/OrthancStone/Sources/Platforms/Native/NativeEnvironment.h	Wed Oct 21 14:40:48 2026 +0200
@@ -24,7 +24,7 @@
 #pragma once
 
 #include "../../Oracle/IEnvironment.h"
-#include "RunnableThread.h"
+#include "PeriodicRunnableThread.h"
 
 #include <MultiThreading/SharedMessageQueue.h>
 
@@ -42,7 +42,7 @@
     // TODO Refactoring - Is it necessary to have "recursive_mutex", not plain "mutex"?
     boost::recursive_mutex       mutex_;  // Main mutex of the application, to go single-threaded
     Orthanc::SharedMessageQueue  notificationQueue_;
-    RunnableThread               notificationThread_;
+    PeriodicRunnableThread       notificationThread_;
     unsigned int                 countLocks_;  // Only for debugging
 
   public:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancStone/Sources/Platforms/Native/PeriodicRunnableThread.cpp	Wed Oct 21 14:40:48 2026 +0200
@@ -0,0 +1,105 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "PeriodicRunnableThread.h"
+
+#include <OrthancException.h>
+
+
+namespace OrthancStone
+{
+  void PeriodicRunnableThread::Worker(PeriodicRunnableThread* that)
+  {
+    for (;;)
+    {
+      {
+        boost::mutex::scoped_lock lock(that->mutex_);
+        if (that->state_ != State_Running)
+        {
+          return;
+        }
+      }
+
+      that->runnable_->Run();
+
+      if (that->timeResolution_ != 0)
+      {
+        boost::this_thread::sleep(boost::posix_time::milliseconds(that->timeResolution_));
+      }
+    }
+  }
+
+
+  void PeriodicRunnableThread::StopInternal(bool throws)
+  {
+    {
+      boost::mutex::scoped_lock lock(mutex_);
+
+      if (state_ != State_Running)
+      {
+        if (throws)
+        {
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+        }
+      }
+      else
+      {
+        state_ = State_Done;
+      }
+    }
+
+    if (thread_.joinable())
+    {
+      thread_.join();
+    }
+  }
+
+
+  PeriodicRunnableThread::PeriodicRunnableThread(Orthanc::IRunnable* runnable,
+                                                 unsigned int timeResolution) :
+    runnable_(runnable),
+    timeResolution_(timeResolution),
+    state_(State_Initialization)
+  {
+    if (runnable == NULL)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
+    }
+  }
+
+
+  void PeriodicRunnableThread::Start()
+  {
+    boost::mutex::scoped_lock lock(mutex_);
+
+    if (state_ != State_Initialization)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      state_ = State_Running;
+      thread_ = boost::thread(Worker, this);
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancStone/Sources/Platforms/Native/PeriodicRunnableThread.h	Wed Oct 21 14:40:48 2026 +0200
@@ -0,0 +1,78 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include <OrthancFramework.h>   // Needed before IRunnable in Orthanc <= 1.13.0
+
+#include <Compatibility.h>
+#include <MultiThreading/IRunnable.h>
+
+#include <boost/thread.hpp>
+
+
+namespace OrthancStone
+{
+  // This is a thread that periodically executes a runnable
+  class PeriodicRunnableThread : public boost::noncopyable
+  {
+  private:
+    enum State
+    {
+      State_Initialization,
+      State_Running,
+      State_Done
+    };
+
+    static void Worker(PeriodicRunnableThread* that);
+
+    void StopInternal(bool throws);
+
+    boost::mutex                         mutex_;
+    std::unique_ptr<Orthanc::IRunnable>  runnable_;
+    unsigned int                         timeResolution_;
+    volatile State                       state_;
+    boost::thread                        thread_;
+
+  public:
+    PeriodicRunnableThread(Orthanc::IRunnable* runnable,
+                           unsigned int timeResolution);
+
+    ~PeriodicRunnableThread()
+    {
+      StopInternal(false /* no exception in destructors */);
+    }
+
+    void Start();
+
+    void Stop()
+    {
+      StopInternal(true);
+    }
+
+    Orthanc::IRunnable& GetRunnable() const
+    {
+      return *runnable_;
+    }
+  };
+}
--- a/OrthancStone/Sources/Platforms/Native/RunnableThread.cpp	Sun Oct 11 11:21:37 2026 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/**
- * Stone of Orthanc
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2023 Osimis S.A., Belgium
- * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/>.
- **/
-
-
-#include "RunnableThread.h"
-
-#include <OrthancException.h>
-
-
-namespace OrthancStone
-{
-  void RunnableThread::Worker(RunnableThread* that)
-  {
-    for (;;)
-    {
-      {
-        boost::mutex::scoped_lock lock(that->mutex_);
-        if (that->state_ != State_Running)
-        {
-          return;
-        }
-      }
-
-      that->runnable_->Run();
-
-      if (that->timeResolution_ != 0)
-      {
-        boost::this_thread::sleep(boost::posix_time::milliseconds(that->timeResolution_));
-      }
-    }
-  }
-
-
-  void RunnableThread::StopInternal(bool throws)
-  {
-    {
-      boost::mutex::scoped_lock lock(mutex_);
-
-      if (state_ != State_Running)
-      {
-        if (throws)
-        {
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
-        }
-      }
-      else
-      {
-        state_ = State_Done;
-      }
-    }
-
-    if (thread_.joinable())
-    {
-      thread_.join();
-    }
-  }
-
-
-  RunnableThread::RunnableThread(Orthanc::IRunnable* runnable,
-                                 unsigned int timeResolution) :
-    runnable_(runnable),
-    timeResolution_(timeResolution),
-    state_(State_Initialization)
-  {
-    if (runnable == NULL)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
-    }
-  }
-
-
-  void RunnableThread::Start()
-  {
-    boost::mutex::scoped_lock lock(mutex_);
-
-    if (state_ != State_Initialization)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
-    }
-    else
-    {
-      state_ = State_Running;
-      thread_ = boost::thread(Worker, this);
-    }
-  }
-}
--- a/OrthancStone/Sources/Platforms/Native/RunnableThread.h	Sun Oct 11 11:21:37 2026 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
-/**
- * Stone of Orthanc
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2023 Osimis S.A., Belgium
- * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/>.
- **/
-
-
-#pragma once
-
-#include <OrthancFramework.h>   // Needed before IRunnable in Orthanc <= 1.13.0
-
-#include <Compatibility.h>
-#include <MultiThreading/IRunnable.h>
-
-#include <boost/thread.hpp>
-
-
-namespace OrthancStone
-{
-  // This is a thread that periodically executes a runnable
-  class RunnableThread : public boost::noncopyable
-  {
-  private:
-    enum State
-    {
-      State_Initialization,
-      State_Running,
-      State_Done
-    };
-
-    static void Worker(RunnableThread* that);
-
-    void StopInternal(bool throws);
-
-    boost::mutex                         mutex_;
-    std::unique_ptr<Orthanc::IRunnable>  runnable_;
-    unsigned int                         timeResolution_;
-    volatile State                       state_;
-    boost::thread                        thread_;
-
-  public:
-    RunnableThread(Orthanc::IRunnable* runnable,
-                   unsigned int timeResolution);
-
-    ~RunnableThread()
-    {
-      StopInternal(false /* no exception in destructors */);
-    }
-
-    void Start();
-
-    void Stop()
-    {
-      StopInternal(true);
-    }
-
-    Orthanc::IRunnable& GetRunnable() const
-    {
-      return *runnable_;
-    }
-  };
-}
--- a/OrthancStone/Sources/Platforms/Native/ThreadedOracle.h	Sun Oct 11 11:21:37 2026 +0200
+++ b/OrthancStone/Sources/Platforms/Native/ThreadedOracle.h	Wed Oct 21 14:40:48 2026 +0200
@@ -44,7 +44,7 @@
 
 #include "../../Oracle/OracleCallback.h"
 #include "../../StoneApplication.h"
-#include "RunnableThread.h"
+#include "PeriodicRunnableThread.h"
 
 #include <MultiThreading/ThreadPool.h>
 
@@ -58,7 +58,7 @@
     class SleepRunnable;
 
     StoneApplication::Configuration  configuration_;
-    RunnableThread                   sleepingThread_;
+    PeriodicRunnableThread           sleepingThread_;
     Orthanc::ThreadPool              threadPool_;
 
 #if ORTHANC_ENABLE_DCMTK == 1