Mercurial > hg > orthanc-wsi
changeset 150:442102e14933
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 09:55:24 +0200 |
parents | 954f45b6e60c |
children | fb8d4cd2f618 b798d200ac90 |
files | Applications/CMakeLists.txt Framework/Semaphore.cpp Framework/Semaphore.h ViewerPlugin/CMakeLists.txt ViewerPlugin/Plugin.cpp |
diffstat | 5 files changed, 118 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/CMakeLists.txt Fri May 04 10:33:44 2018 +0200 +++ b/Applications/CMakeLists.txt Tue Jul 17 09:55:24 2018 +0200 @@ -119,6 +119,7 @@ add_definitions( -DHAS_ORTHANC_EXCEPTION=1 + -DORTHANC_ENABLE_LOGGING_PLUGIN=0 )
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Semaphore.cpp Tue Jul 17 09:55:24 2018 +0200 @@ -0,0 +1,50 @@ +/** + * 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_++; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Semaphore.h Tue Jul 17 09:55:24 2018 +0200 @@ -0,0 +1,61 @@ +/** + * 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 Fri May 04 10:33:44 2018 +0200 +++ b/ViewerPlugin/CMakeLists.txt Tue Jul 17 09:55:24 2018 +0200 @@ -68,6 +68,7 @@ add_definitions( -DHAS_ORTHANC_EXCEPTION=1 + -DORTHANC_ENABLE_LOGGING_PLUGIN=1 ) if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR @@ -153,6 +154,7 @@ ${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 Fri May 04 10:33:44 2018 +0200 +++ b/ViewerPlugin/Plugin.cpp Tue Jul 17 09:55:24 2018 +0200 @@ -23,10 +23,10 @@ #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 <Plugins/Samples/Common/OrthancPluginCppWrapper.h> #include <Plugins/Samples/Common/OrthancPluginConnection.h> @@ -39,7 +39,7 @@ std::auto_ptr<OrthancPlugins::OrthancPluginConnection> orthanc_; std::auto_ptr<OrthancWSI::DicomPyramidCache> cache_; -std::auto_ptr<Orthanc::Semaphore> transcoderSemaphore_; +std::auto_ptr<OrthancWSI::Semaphore> transcoderSemaphore_; static void AnswerSparseTile(OrthancPluginRestOutput* output, @@ -183,7 +183,7 @@ // decompress the raw tile std::auto_ptr<Orthanc::ImageAccessor> decoded; - Orthanc::Semaphore::Locker locker(*transcoderSemaphore_); + OrthancWSI::Semaphore::Locker locker(*transcoderSemaphore_); switch (compression) { @@ -319,7 +319,7 @@ threads = 1; } - transcoderSemaphore_.reset(new Orthanc::Semaphore(threads)); + transcoderSemaphore_.reset(new OrthancWSI::Semaphore(threads)); char info[1024]; sprintf(info, "The whole-slide imaging plugin will use at most %u threads to transcode the tiles", threads);