Source · fairmq/tools/
Semaphore.hpublic header
Defines struct fair::mq::tools::Semaphore, struct fair::mq::tools::SharedSemaphore.
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_H10#define FAIR_MQ_TOOLS_SEMAPHORE_H11 12#include <condition_variable>13#include <cstdint>14#include <functional>15#include <memory>16#include <mutex>17 18namespace fair::mq::tools19{20 21/**22 * @struct Semaphore Semaphore.h <fairmq/tools/Semaphore.h>23 * @brief A simple blocking semaphore.24 */25struct Semaphore26{27 Semaphore();28 explicit Semaphore(std::size_t initial_count);29 30 auto Wait() -> void;31 auto Signal() -> void;32 auto GetCount() const -> std::size_t;33 34private:35 std::size_t fCount;36 mutable std::mutex fMutex;37 std::condition_variable fCv;38};39 40/**41 * @struct SharedSemaphore Semaphore.h <fairmq/tools/Semaphore.h>42 * @brief A simple copyable blocking semaphore.43 */44struct SharedSemaphore45{46 SharedSemaphore();47 explicit SharedSemaphore(std::size_t initial_count);48 49 auto Wait() -> void;50 auto Signal() -> void;51 auto GetCount() const -> std::size_t;52 53private:54 std::shared_ptr<Semaphore> fSemaphore;55};56 57} // namespace fair::mq::tools58 59#endif /* FAIR_MQ_TOOLS_SEMAPHORE_H */