Mercurial > hg > orthanc-stone
changeset 2390:ba477e5a4981 refactoring tip
class PeriodicRunnableThread moved to orthanc
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Wed, 21 Oct 2026 14:53:38 +0200 |
| parents | fc70ff98a5c7 |
| children | |
| 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/ThreadedOracle.h |
| diffstat | 5 files changed, 7 insertions(+), 191 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancStone/Resources/CMake/OrthancStoneConfiguration.cmake Wed Oct 21 14:40:48 2026 +0200 +++ b/OrthancStone/Resources/CMake/OrthancStoneConfiguration.cmake Wed Oct 21 14:53:38 2026 +0200 @@ -221,7 +221,6 @@ 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 ) endif()
--- a/OrthancStone/Sources/Platforms/Native/NativeEnvironment.h Wed Oct 21 14:40:48 2026 +0200 +++ b/OrthancStone/Sources/Platforms/Native/NativeEnvironment.h Wed Oct 21 14:53:38 2026 +0200 @@ -24,8 +24,8 @@ #pragma once #include "../../Oracle/IEnvironment.h" -#include "PeriodicRunnableThread.h" +#include <MultiThreading/PeriodicRunnableThread.h> #include <MultiThreading/SharedMessageQueue.h> @@ -40,10 +40,10 @@ class ErrorNotification; // 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_; - PeriodicRunnableThread notificationThread_; - unsigned int countLocks_; // Only for debugging + boost::recursive_mutex mutex_; // Main mutex of the application, to go single-threaded + Orthanc::SharedMessageQueue notificationQueue_; + Orthanc::PeriodicRunnableThread notificationThread_; + unsigned int countLocks_; // Only for debugging public: class Lock : public ILock
--- a/OrthancStone/Sources/Platforms/Native/PeriodicRunnableThread.cpp Wed Oct 21 14:40:48 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 "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); - } - } -}
--- a/OrthancStone/Sources/Platforms/Native/PeriodicRunnableThread.h Wed Oct 21 14:40:48 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 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/ThreadedOracle.h Wed Oct 21 14:40:48 2026 +0200 +++ b/OrthancStone/Sources/Platforms/Native/ThreadedOracle.h Wed Oct 21 14:53:38 2026 +0200 @@ -44,8 +44,8 @@ #include "../../Oracle/OracleCallback.h" #include "../../StoneApplication.h" -#include "PeriodicRunnableThread.h" +#include <MultiThreading/PeriodicRunnableThread.h> #include <MultiThreading/ThreadPool.h> @@ -58,7 +58,7 @@ class SleepRunnable; StoneApplication::Configuration configuration_; - PeriodicRunnableThread sleepingThread_; + Orthanc::PeriodicRunnableThread sleepingThread_; Orthanc::ThreadPool threadPool_; #if ORTHANC_ENABLE_DCMTK == 1
