# HG changeset patch # User Sebastien Jodogne # Date 1532693186 -7200 # Node ID b798d200ac9080724089733ccc27c1e35eccbdf4 # Parent 442102e149337d920efb05fb267abbb40b8b96c9 using Semaphore from Orthanc framework diff -r 442102e14933 -r b798d200ac90 Framework/Semaphore.cpp --- 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 . - **/ - - -#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_++; - } -} diff -r 442102e14933 -r b798d200ac90 Framework/Semaphore.h --- 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 . - **/ - - -#pragma once - -#include -#include - -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(); - } - }; - }; -} diff -r 442102e14933 -r b798d200ac90 ViewerPlugin/CMakeLists.txt --- 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 diff -r 442102e14933 -r b798d200ac90 ViewerPlugin/Plugin.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 #include +#include #include +#include #include #include @@ -39,7 +40,7 @@ std::auto_ptr orthanc_; std::auto_ptr cache_; -std::auto_ptr transcoderSemaphore_; +std::auto_ptr transcoderSemaphore_; static void AnswerSparseTile(OrthancPluginRestOutput* output, @@ -183,7 +184,7 @@ // decompress the raw tile std::auto_ptr 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);