Mercurial > hg > orthanc
diff Core/MultiThreading/Semaphore.h @ 2884:497a637366b4 db-changes
integration mainline->db-changes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 12 Oct 2018 15:18:10 +0200 |
parents | 6e7e5ed91c2d f790999a250a |
children | 4e43e67f8ecf |
line wrap: on
line diff
--- a/Core/MultiThreading/Semaphore.h Thu Oct 29 11:25:45 2015 +0100 +++ b/Core/MultiThreading/Semaphore.h Fri Oct 12 15:18:10 2018 +0200 @@ -1,7 +1,8 @@ /** * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics + * 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 General Public License as @@ -43,12 +44,30 @@ unsigned int count_; boost::mutex mutex_; boost::condition_variable condition_; + + void Release(); + + void Acquire(); public: explicit Semaphore(unsigned int count); - void Release(); + class Locker : public boost::noncopyable + { + private: + Semaphore& that_; - void Acquire(); + public: + explicit Locker(Semaphore& that) : + that_(that) + { + that_.Acquire(); + } + + ~Locker() + { + that_.Release(); + } + }; }; }