Mercurial > hg > orthanc-wsi
changeset 153:b798d200ac90
using Semaphore from Orthanc framework
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Jul 2018 14:06:26 +0200 |
parents | 442102e14933 |
children | 32a94bbb7d05 |
files | Framework/Semaphore.cpp Framework/Semaphore.h ViewerPlugin/CMakeLists.txt ViewerPlugin/Plugin.cpp |
diffstat | 4 files changed, 6 insertions(+), 123 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Semaphore.cpp Tue Jul 17 09:55:24 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2018 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Affero 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 - * Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - **/ - - -#include "Semaphore.h" - - -namespace OrthancWSI -{ - Semaphore::Semaphore(unsigned int count) : count_(count) - { - } - - void Semaphore::Release() - { - boost::mutex::scoped_lock lock(mutex_); - - count_++; - condition_.notify_one(); - } - - void Semaphore::Acquire() - { - boost::mutex::scoped_lock lock(mutex_); - - while (count_ == 0) - { - condition_.wait(lock); - } - - count_++; - } -}
--- a/Framework/Semaphore.h Tue Jul 17 09:55:24 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2018 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Affero 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 - * Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - **/ - - -#pragma once - -#include <boost/noncopyable.hpp> -#include <boost/thread.hpp> - -namespace OrthancWSI -{ - class Semaphore : public boost::noncopyable - { - private: - unsigned int count_; - boost::mutex mutex_; - boost::condition_variable condition_; - - public: - explicit Semaphore(unsigned int count); - - void Release(); - - void Acquire(); - - class Locker : public boost::noncopyable - { - private: - Semaphore& that_; - - public: - explicit Locker(Semaphore& that) : - that_(that) - { - that_.Acquire(); - } - - ~Locker() - { - that_.Release(); - } - }; - }; -}
--- a/ViewerPlugin/CMakeLists.txt Tue Jul 17 09:55:24 2018 +0200 +++ b/ViewerPlugin/CMakeLists.txt Fri Jul 27 14:06:26 2018 +0200 @@ -154,7 +154,6 @@ ${ORTHANC_WSI_DIR}/Framework/Inputs/PyramidWithRawTiles.cpp ${ORTHANC_WSI_DIR}/Framework/Jpeg2000Reader.cpp ${ORTHANC_WSI_DIR}/Framework/Jpeg2000Writer.cpp - ${ORTHANC_WSI_DIR}/Framework/Semaphore.cpp ${ORTHANC_ROOT}/Plugins/Samples/Common/DicomDatasetReader.cpp ${ORTHANC_ROOT}/Plugins/Samples/Common/DicomPath.cpp
--- a/ViewerPlugin/Plugin.cpp Tue Jul 17 09:55:24 2018 +0200 +++ b/ViewerPlugin/Plugin.cpp Fri Jul 27 14:06:26 2018 +0200 @@ -23,11 +23,12 @@ #include "DicomPyramidCache.h" #include "../Framework/Jpeg2000Reader.h" -#include "../Framework/Semaphore.h" #include <Core/Images/ImageProcessing.h> #include <Core/Images/PngWriter.h> +#include <Core/MultiThreading/Semaphore.h> #include <Core/OrthancException.h> +#include <Core/SystemToolbox.h> #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> #include <Plugins/Samples/Common/OrthancPluginConnection.h> @@ -39,7 +40,7 @@ std::auto_ptr<OrthancPlugins::OrthancPluginConnection> orthanc_; std::auto_ptr<OrthancWSI::DicomPyramidCache> cache_; -std::auto_ptr<OrthancWSI::Semaphore> transcoderSemaphore_; +std::auto_ptr<Orthanc::Semaphore> transcoderSemaphore_; static void AnswerSparseTile(OrthancPluginRestOutput* output, @@ -183,7 +184,7 @@ // decompress the raw tile std::auto_ptr<Orthanc::ImageAccessor> decoded; - OrthancWSI::Semaphore::Locker locker(*transcoderSemaphore_); + Orthanc::Semaphore::Locker locker(*transcoderSemaphore_); switch (compression) { @@ -312,14 +313,8 @@ // Limit the number of PNG transcoders to the number of available // hardware threads (e.g. number of CPUs or cores or // hyperthreading units) - unsigned int threads = boost::thread::hardware_concurrency(); - - if (threads <= 0) - { - threads = 1; - } - - transcoderSemaphore_.reset(new OrthancWSI::Semaphore(threads)); + unsigned int threads = Orthanc::SystemToolbox::GetHardwareConcurrency(); + transcoderSemaphore_.reset(new Orthanc::Semaphore(threads)); char info[1024]; sprintf(info, "The whole-slide imaging plugin will use at most %u threads to transcode the tiles", threads);