FairMQ  1.4.14
C++ Message Queuing Library and Framework
Semaphore.h
1 /********************************************************************************
2  * Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #ifndef FAIR_MQ_TOOLS_SEMAPHORE_H
10 #define FAIR_MQ_TOOLS_SEMAPHORE_H
11 
12 #include <condition_variable>
13 #include <cstdint>
14 #include <functional>
15 #include <memory>
16 #include <mutex>
17 
18 namespace fair {
19 namespace mq {
20 namespace tools {
21 
26 struct Semaphore
27 {
28  Semaphore();
29  explicit Semaphore(std::size_t initial_count);
30 
31  auto Wait() -> void;
32  auto Signal() -> void;
33  auto GetCount() const -> std::size_t;
34 
35 private:
36  std::size_t fCount;
37  mutable std::mutex fMutex;
38  std::condition_variable fCv;
39 };
40 
46 {
48  explicit SharedSemaphore(std::size_t initial_count);
49 
50  auto Wait() -> void;
51  auto Signal() -> void;
52  auto GetCount() const -> std::size_t;
53 
54 private:
55  std::shared_ptr<Semaphore> fSemaphore;
56 };
57 
58 } /* namespace tools */
59 } /* namespace mq */
60 } /* namespace fair */
61 
62 #endif /* FAIR_MQ_TOOLS_SEMAPHORE_H */
A simple blocking semaphore.
Definition: Semaphore.h:26
A simple copyable blocking semaphore.
Definition: Semaphore.h:45
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23

privacy