# HG changeset patch # User Sebastien Jodogne # Date 1792587218 -7200 # Node ID ba477e5a4981a88919a100d5b5e14d76dcba08be # Parent fc70ff98a5c7312733e188d9f22b96a9a5a27d3a class PeriodicRunnableThread moved to orthanc diff -r fc70ff98a5c7 -r ba477e5a4981 OrthancStone/Resources/CMake/OrthancStoneConfiguration.cmake --- 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() diff -r fc70ff98a5c7 -r ba477e5a4981 OrthancStone/Sources/Platforms/Native/NativeEnvironment.h --- 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 #include @@ -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 diff -r fc70ff98a5c7 -r ba477e5a4981 OrthancStone/Sources/Platforms/Native/PeriodicRunnableThread.cpp --- 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 - * . - **/ - - -#include "PeriodicRunnableThread.h" - -#include - - -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); - } - } -} diff -r fc70ff98a5c7 -r ba477e5a4981 OrthancStone/Sources/Platforms/Native/PeriodicRunnableThread.h --- 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 - * . - **/ - - -#pragma once - -#include // Needed before IRunnable in Orthanc <= 1.13.0 - -#include -#include - -#include - - -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 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_; - } - }; -} diff -r fc70ff98a5c7 -r ba477e5a4981 OrthancStone/Sources/Platforms/Native/ThreadedOracle.h --- 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 #include @@ -58,7 +58,7 @@ class SleepRunnable; StoneApplication::Configuration configuration_; - PeriodicRunnableThread sleepingThread_; + Orthanc::PeriodicRunnableThread sleepingThread_; Orthanc::ThreadPool threadPool_; #if ORTHANC_ENABLE_DCMTK == 1